Commit cd59886d authored by stuartmorgan's avatar stuartmorgan Committed by Commit bot

Upstream more leaf files in ios/web/web_state

Also updates a few related files that had become stale relative to
downstream.

BUG=464810

Review URL: https://codereview.chromium.org/1107083002

Cr-Commit-Position: refs/heads/master@{#327081}
parent 95a989fc
include_rules = [ include_rules = [
"+crypto",
"+ios/public/provider/web", "+ios/public/provider/web",
"+ios/net", "+ios/net",
"+ios/web", "+ios/web",
......
...@@ -90,6 +90,7 @@ ...@@ -90,6 +90,7 @@
'public/user_metrics.h', 'public/user_metrics.h',
'public/web_client.h', 'public/web_client.h',
'public/web_client.mm', 'public/web_client.mm',
'public/web_state/credential.h',
'public/web_state/crw_native_content.h', 'public/web_state/crw_native_content.h',
'public/web_state/crw_native_content_provider.h', 'public/web_state/crw_native_content_provider.h',
'public/web_state/crw_web_controller_observer.h', 'public/web_state/crw_web_controller_observer.h',
...@@ -119,11 +120,20 @@ ...@@ -119,11 +120,20 @@
'weak_nsobject_counter.mm', 'weak_nsobject_counter.mm',
'web_state/blocked_popup_info.h', 'web_state/blocked_popup_info.h',
'web_state/blocked_popup_info.mm', 'web_state/blocked_popup_info.mm',
'web_state/credential.cc',
'web_state/crw_recurring_task_delegate.h', 'web_state/crw_recurring_task_delegate.h',
'web_state/js/credential_util.h',
'web_state/js/credential_util.mm',
'web_state/js/crw_js_early_script_manager.h', 'web_state/js/crw_js_early_script_manager.h',
'web_state/js/crw_js_early_script_manager.mm', 'web_state/js/crw_js_early_script_manager.mm',
'web_state/js/crw_js_injection_manager.mm', 'web_state/js/crw_js_injection_manager.mm',
'web_state/js/crw_js_injection_receiver.mm', 'web_state/js/crw_js_injection_receiver.mm',
'web_state/js/crw_js_invoke_parameter_queue.h',
'web_state/js/crw_js_invoke_parameter_queue.mm',
'web_state/js/crw_js_plugin_placeholder_manager.h',
'web_state/js/crw_js_plugin_placeholder_manager.mm',
'web_state/js/crw_js_window_id_manager.h',
'web_state/js/crw_js_window_id_manager.mm',
'web_state/js/page_script_util.h', 'web_state/js/page_script_util.h',
'web_state/js/page_script_util.mm', 'web_state/js/page_script_util.mm',
'web_state/ui/crw_context_menu_provider.h', 'web_state/ui/crw_context_menu_provider.h',
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_WEB_STATE_CREDENTIAL_H_
#define IOS_WEB_PUBLIC_WEB_STATE_CREDENTIAL_H_
#include "base/strings/string16.h"
#include "url/gurl.h"
namespace web {
// Indicates the specific type of a Credential object.
enum CredentialType {
CREDENTIAL_TYPE_EMPTY = 0,
CREDENTIAL_TYPE_LOCAL,
CREDENTIAL_TYPE_FEDERATED,
CREDENTIAL_TYPE_LAST = CREDENTIAL_TYPE_FEDERATED
};
// Represents an instance of the JavaScript Credential type.
struct Credential {
Credential();
~Credential();
// The specific type of this credential.
CredentialType type;
// An identifier for the credential.
base::string16 id;
// A human-understandable name corresponding to the credential.
base::string16 name;
// The URL of the user's avatar.
GURL avatar_url;
// The password for a local credential.
base::string16 password;
// The federation URL for a federated credential.
GURL federation_url;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_WEB_STATE_CREDENTIAL_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <string> #include <string>
@class CRWWebController; @class CRWWebController;
@class CRWWebViewProxy; @protocol CRWWebViewProxy;
class GURL; class GURL;
@class UIWebView; @class UIWebView;
...@@ -33,38 +33,6 @@ class DictionaryValue; ...@@ -33,38 +33,6 @@ class DictionaryValue;
// DEPRECATED: Use WebStateObserver instead. // DEPRECATED: Use WebStateObserver instead.
- (void)pageLoaded:(CRWWebController*)webController; - (void)pageLoaded:(CRWWebController*)webController;
// Called when a form is being submitted.
- (void)documentSubmit:(CRWWebController*)webController
formName:(const std::string&)formName
userInteraction:(BOOL)userInteraction;
// Called when the user is typing on a form field, with |error| indicating if
// there is any error when parsing the form field information. Currently these
// events will not be sent if the Disable Autofill experiment is set.
- (void)formActivity:(CRWWebController*)webController
formName:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
error:(bool)error;
// Identical to |formActivity:formName:fieldName:type:value:error:|, but
// indicates that the activity was triggered by typing the key specified by
// |keyCode|.
- (void)formActivity:(CRWWebController*)webController
formName:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
keyCode:(int)keyCode
error:(bool)error;
// The page requested autocomplete.
- (void)requestAutocomplete:(CRWWebController*)webController
sourceURL:(const GURL&)sourceURL
formName:(const std::string&)formName
userInteraction:(BOOL)userInteraction;
// Called when the web controller is about to close. // Called when the web controller is about to close.
- (void)webControllerWillClose:(CRWWebController*)webController; - (void)webControllerWillClose:(CRWWebController*)webController;
...@@ -77,7 +45,7 @@ class DictionaryValue; ...@@ -77,7 +45,7 @@ class DictionaryValue;
originURL:(const GURL&)originURL; originURL:(const GURL&)originURL;
// Gives CRWWebControllerObservers access to the CRWWebViewProxy. // Gives CRWWebControllerObservers access to the CRWWebViewProxy.
- (void)setWebViewProxy:(CRWWebViewProxy*)webView - (void)setWebViewProxy:(id<CRWWebViewProxy>)webView
controller:(CRWWebController*)webController; controller:(CRWWebController*)webController;
@end @end
......
...@@ -44,10 +44,6 @@ ...@@ -44,10 +44,6 @@
// Used by the CRWWebViewProxy to set the UIScrollView to be managed. // Used by the CRWWebViewProxy to set the UIScrollView to be managed.
- (void)setScrollView:(UIScrollView*)scrollView; - (void)setScrollView:(UIScrollView*)scrollView;
// Copies all display properties that can be set on a CRWWebViewScrollViewProxy
// from the underlying UIScrollView into |scrollView|.
- (void)copyPropertiesToScrollView:(UIScrollView*)scrollView;
// Adds |observer| to subscribe to change notifications. // Adds |observer| to subscribe to change notifications.
- (void)addObserver:(id<CRWWebViewScrollViewProxyObserver>)observer; - (void)addObserver:(id<CRWWebViewScrollViewProxyObserver>)observer;
......
...@@ -14,6 +14,7 @@ class GURL; ...@@ -14,6 +14,7 @@ class GURL;
namespace web { namespace web {
struct Credential;
struct FaviconURL; struct FaviconURL;
struct LoadCommittedDetails; struct LoadCommittedDetails;
class WebState; class WebState;
...@@ -42,6 +43,12 @@ class WebStateObserver { ...@@ -42,6 +43,12 @@ class WebStateObserver {
virtual void NavigationItemCommitted( virtual void NavigationItemCommitted(
const LoadCommittedDetails& load_details) {} const LoadCommittedDetails& load_details) {}
// Called when the current page has started loading.
virtual void DidStartLoading() {}
// Called when the current page has stopped loading.
virtual void DidStopLoading() {}
// Called when the current page is loaded. // Called when the current page is loaded.
virtual void PageLoaded(PageLoadCompletionStatus load_completion_status) {} virtual void PageLoaded(PageLoadCompletionStatus load_completion_status) {}
...@@ -80,6 +87,54 @@ class WebStateObserver { ...@@ -80,6 +87,54 @@ class WebStateObserver {
// Invoked when new favicon URL candidates are received. // Invoked when new favicon URL candidates are received.
virtual void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) {} virtual void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to request a credential from the browser. If |suppress_ui|
// is true, the browser MUST NOT show any UI to the user. If this means that
// no credential will be returned to the page, so be it. Otherwise, the
// browser may show the user any UI that is necessary to get a Credential and
// return it to the page. |federations| specifies a list of acceptable
// federation providers. |user_interaction| indicates whether the API was
// invoked in response to a user interaction. Responses to the page should
// provide the specified |request_id|.
virtual void CredentialsRequested(int request_id,
const GURL& source_url,
bool suppress_ui,
const std::vector<std::string>& federations,
bool is_user_initiated) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to notify the browser that the user signed in. |credential|
// specifies the credential that was used to sign in. Responses to the page
// should provide the specified |request_id|.
virtual void SignedIn(int request_id,
const GURL& source_url,
const web::Credential& credential) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to notify the browser that the user signed in without
// specifying the credential that was used. Responses to the page should
// provide the specified |request_id|.
virtual void SignedIn(int request_id, const GURL& source_url) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to notify the browser that the user signed out. Responses
// to the page should provide the specified |request_id|.
virtual void SignedOut(int request_id, const GURL& source_url) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to notify the browser that the user failed to sign in.
// |credential| specifies the credential that failed to sign in. Responses
// to the page should provide the specified |request_id|.
virtual void SignInFailed(int request_id,
const GURL& source_url,
const web::Credential& credential) {}
// Notifies the observer that the credential manager API was invoked from
// |source_url| to notify the browser that the user failed to sign in without
// specifying the credential that failed. Responses to the page should provide
// the specified |request_id|.
virtual void SignInFailed(int request_id, const GURL& source_url) {}
// Invoked when the WebState is being destroyed. Gives subclasses a chance // Invoked when the WebState is being destroyed. Gives subclasses a chance
// to cleanup. // to cleanup.
virtual void WebStateDestroyed() {} virtual void WebStateDestroyed() {}
......
...@@ -70,6 +70,12 @@ class GURL; ...@@ -70,6 +70,12 @@ class GURL;
// is no longer valid. // is no longer valid.
- (void)webStateDestroyed:(web::WebState*)webState; - (void)webStateDestroyed:(web::WebState*)webState;
// Invoked by WebStateObserverBridge::DidStopLoading.
- (void)webStateDidStopLoading:(web::WebState*)webState;
// Invoked by WebStateObserverBridge::DidStartLoading.
- (void)webStateDidStartLoading:(web::WebState*)webState;
@end @end
namespace web { namespace web {
...@@ -108,6 +114,8 @@ class WebStateObserverBridge : public web::WebStateObserver { ...@@ -108,6 +114,8 @@ class WebStateObserverBridge : public web::WebStateObserver {
bool user_initiated) override; bool user_initiated) override;
void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) override; void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) override;
void WebStateDestroyed() override; void WebStateDestroyed() override;
void DidStartLoading() override;
void DidStopLoading() override;
private: private:
base::WeakNSProtocol<id<CRWWebStateObserver>> observer_; base::WeakNSProtocol<id<CRWWebStateObserver>> observer_;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/web/public/web_state/credential.h"
namespace web {
Credential::Credential() = default;
Credential::~Credential() = default;
} // namespace web
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_JS_CREDENTIAL_UTIL_H_
#define IOS_WEB_WEB_STATE_JS_CREDENTIAL_UTIL_H_
namespace base {
class DictionaryValue;
} // namespace base
namespace web {
struct Credential;
// Populates |credential| from |value|, returning true if successful and false
// otherwise. |value| must contain the following string->string key/value
// pairs:
//
// "type": one of "LocalCredential" of "FederatedCredential"
// "id": a string (possibly empty)
//
// The following pairs are optional:
//
// "name": a string (possibly empty)
// "avatarURL": a valid URL as a string
//
// If "type" is "LocalCredential", then |value| must contain
//
// "password" a string (possibly empty)
//
// If "type" is "FederatedCredential", then |value| must contain
//
// "federation": a valid URL as a string
//
// If passed a |value| that doesn't meet these restrictions, |credential| will
// not be modified and false will be returned. |credential| must not be null.
bool DictionaryValueToCredential(const base::DictionaryValue& value,
Credential* credential);
// Serializes |credential| to |value|.
void CredentialToDictionaryValue(const Credential& credential,
base::DictionaryValue* value);
} // namespace web
#endif // IOS_WEB_WEB_STATE_JS_CREDENTIAL_UTIL_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/web/web_state/js/credential_util.h"
#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "ios/web/public/web_state/credential.h"
#include "url/gurl.h"
namespace {
// "type" value for a DictionaryValue representation of LocalCredential.
const char* kLocalCredentialType = "LocalCredential";
// "type" value for a DictionaryValue representation of FederatedCredential.
const char* kFederatedCredentialType = "FederatedCredential";
} // namespace
namespace web {
bool DictionaryValueToCredential(const base::DictionaryValue& value,
Credential* credential) {
DCHECK(credential);
base::string16 type;
if (!value.GetString("type", &type))
return false;
CredentialType credential_type;
if (type == base::ASCIIToUTF16(kLocalCredentialType))
credential_type = CredentialType::CREDENTIAL_TYPE_LOCAL;
else if (type == base::ASCIIToUTF16(kFederatedCredentialType))
credential_type = CredentialType::CREDENTIAL_TYPE_FEDERATED;
else
return false;
base::string16 id;
if (!value.GetString("id", &id))
return false;
base::string16 name;
value.GetString("name", &name);
base::string16 avatar;
GURL avatar_url;
if (value.GetString("avatarURL", &avatar)) {
avatar_url = GURL(avatar);
if (!avatar_url.is_valid())
return false;
}
base::string16 password;
if (credential_type == CredentialType::CREDENTIAL_TYPE_LOCAL &&
!value.GetString("password", &password)) {
return false;
}
base::string16 federation;
GURL federation_url;
if (credential_type == CredentialType::CREDENTIAL_TYPE_FEDERATED) {
if (!value.GetString("federation", &federation))
return false;
federation_url = GURL(federation);
if (!federation_url.is_valid())
return false;
}
credential->type = credential_type;
credential->id = id;
credential->name = name;
credential->avatar_url = avatar_url;
credential->password = password;
credential->federation_url = federation_url;
return true;
}
void CredentialToDictionaryValue(const Credential& credential,
base::DictionaryValue* value) {
switch (credential.type) {
case CredentialType::CREDENTIAL_TYPE_LOCAL:
value->SetString("type", kLocalCredentialType);
value->SetString("password", credential.password);
break;
case CredentialType::CREDENTIAL_TYPE_FEDERATED:
value->SetString("type", kFederatedCredentialType);
value->SetString("federation", credential.federation_url.spec());
break;
default:
NOTREACHED();
}
value->SetString("id", credential.id);
value->SetString("name", credential.name);
value->SetString("avatarURL", credential.avatar_url.spec());
}
} // web
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#import "ios/web/web_state/js/page_script_util.h"
@implementation CRWJSInjectionManager { @implementation CRWJSInjectionManager {
// JS to inject into the page. This may be nil if it has been purged due to // JS to inject into the page. This may be nil if it has been purged due to
...@@ -111,18 +112,7 @@ ...@@ -111,18 +112,7 @@
} }
- (NSString*)staticInjectionContent { - (NSString*)staticInjectionContent {
DCHECK(self.scriptPath); return web::GetPageScript([self scriptPath]);
NSString* path = [base::mac::FrameworkBundle() pathForResource:self.scriptPath
ofType:@"js"];
DCHECK(path) << "Script file not found: "
<< base::SysNSStringToUTF8(self.scriptPath) << ".js";
NSError* error = nil;
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:&error];
DCHECK(!error) << "Error fetching script: " << [error.description UTF8String];
DCHECK(content);
return content;
} }
- (void)injectDependenciesIfMissing { - (void)injectDependenciesIfMissing {
......
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_JS_CRW_JS_INVOKE_PARAMETER_QUEUE_H_
#define IOS_WEB_WEB_STATE_JS_CRW_JS_INVOKE_PARAMETER_QUEUE_H_
#import <UIKit/UIKit.h>
class GURL;
// Manages access to individual invoke parameters.
@interface CRWJSInvokeParameters : NSObject
// The designated initializer.
- (id)initWithCommandString:(NSString*)commandString
userIsInteracting:(BOOL)userIsInteracting
originURL:(const GURL&)originURL
forWindowId:(NSString*)windowId;
// An escaped string with commands requested by JavaScript.
@property(nonatomic, readonly) NSString* commandString;
// Whether the user was interacting when the command was issued.
@property(nonatomic, readonly) BOOL userIsInteracting;
// Returns window id of the originating window.
@property(nonatomic, readonly) NSString* windowId;
// Returns URL that was current when the crwebinvoke was issued.
@property(nonatomic, readonly) const GURL& originURL;
@end
// Stores parameters passed from JavaScript for deferred processing.
@interface CRWJSInvokeParameterQueue : NSObject
// YES if there are no more queued messages.
@property(nonatomic, readonly) BOOL isEmpty;
// Adds a new item to the queue. |commandString| is the escaped command string,
// |userIsInteracting| is true if the user was interacting with the page,
// |originURL| is the URL the command came from, and |windowId| is the id of the
// window that sent the command.
- (void)addCommandString:(NSString*)commandString
userIsInteracting:(BOOL)userIsInteracting
originURL:(const GURL&)originURL
forWindowId:(NSString*)windowId;
// Removes from |queue_| any CRWJSInvokeParameters whose command string contains
// |commandString|.
- (void)removeCommandString:(NSString*)commandString;
// Removes the oldest item from the queue and returns it.
- (CRWJSInvokeParameters*)popInvokeParameters;
@end
@interface CRWJSInvokeParameterQueue (Testing)
// The number of items in the queue.
@property(nonatomic, readonly) NSUInteger queueLength;
@end
#endif // IOS_WEB_WEB_STATE_JS_CRW_JS_INVOKE_PARAMETER_QUEUE_H_
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/web_state/js/crw_js_invoke_parameter_queue.h"
#import "base/mac/scoped_nsobject.h"
#include "url/gurl.h"
@implementation CRWJSInvokeParameters {
base::scoped_nsobject<NSString> _commandString;
BOOL _userIsInteracting;
base::scoped_nsobject<NSString> _windowId;
GURL _originURL;
}
@synthesize userIsInteracting = _userIsInteracting;
- (id)initWithCommandString:(NSString*)commandString
userIsInteracting:(BOOL)userIsInteracting
originURL:(const GURL&)originURL
forWindowId:(NSString*)windowId {
if ((self = [super init])) {
_commandString.reset([commandString copy]);
_userIsInteracting = userIsInteracting;
_windowId.reset([windowId copy]);
_originURL = originURL;
}
return self;
}
- (NSString*)commandString {
return _commandString.get();
}
- (NSString*)windowId {
return _windowId.get();
}
- (const GURL&)originURL {
return _originURL;
}
@end
@implementation CRWJSInvokeParameterQueue {
base::scoped_nsobject<NSMutableArray> _queue;
}
- (id)init {
if ((self = [super init])) {
// Under normal circumstainces there will be maximum one message queued.
_queue.reset([[NSMutableArray arrayWithCapacity:1] retain]);
}
return self;
}
- (BOOL)isEmpty {
return [_queue count] == 0;
}
- (NSUInteger)queueLength {
return [_queue count];
}
- (void)addCommandString:(NSString*)commandString
userIsInteracting:(BOOL)userIsInteracting
originURL:(const GURL&)originURL
forWindowId:(NSString*)windowId {
base::scoped_nsobject<CRWJSInvokeParameters> invokeParameters(
[[CRWJSInvokeParameters alloc] initWithCommandString:commandString
userIsInteracting:userIsInteracting
originURL:originURL
forWindowId:windowId]);
[_queue addObject:invokeParameters];
}
- (void)removeCommandString:(NSString*)commandString {
NSMutableArray* commandsToRemove = [NSMutableArray array];
for (CRWJSInvokeParameters* params in _queue.get()) {
NSRange range =
[[params commandString] rangeOfString:commandString
options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound)
[commandsToRemove addObject:params];
}
[_queue removeObjectsInArray:commandsToRemove];
}
- (CRWJSInvokeParameters*)popInvokeParameters {
if (![_queue count])
return nil;
CRWJSInvokeParameters* invokeParameters =
[[[_queue objectAtIndex:0] retain] autorelease];
[_queue removeObjectAtIndex:0];
return invokeParameters;
}
@end
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_JS_CRW_JS_PLUGIN_PLACEHOLDER_MANAGER_H_
#define IOS_WEB_WEB_STATE_JS_CRW_JS_PLUGIN_PLACEHOLDER_MANAGER_H_
#import "ios/web/public/web_state/js/crw_js_injection_manager.h"
// Loads the JavaScript file plugin_placeholder.js, which contains logic for
// adding placeholders to plugins on the page. It will be evaluated on a page
// where plugins that need placeholders have been detected.
@interface CRWJSPluginPlaceholderManager : CRWJSInjectionManager
@end
#endif // IOS_WEB_WEB_STATE_JS_CRW_JS_PLUGIN_PLACEHOLDER_MANAGER_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/web/public/web_client.h"
@implementation CRWJSPluginPlaceholderManager
namespace {
// Returns a string with \ and ' escaped, and wrapped in '.
// This is used instead of GetQuotedJSONString because that will convert
// UTF-16 to UTF-8, which can cause problems when injecting scripts depending
// on the page encoding (see crbug.com/302741).
NSString* EscapedQuotedString(NSString* string) {
string = [string stringByReplacingOccurrencesOfString:@"\\"
withString:@"\\\\"];
string = [string stringByReplacingOccurrencesOfString:@"'"
withString:@"\\'"];
return [NSString stringWithFormat:@"'%@'", string];
}
}
#pragma mark -
#pragma mark ProtectedMethods
- (NSString*)scriptPath {
return @"plugin_placeholder";
}
- (NSString*)presenceBeacon {
return @"__gCrWeb.plugin";
}
- (NSString*)staticInjectionContent {
NSString* baseContent = [super staticInjectionContent];
DCHECK(web::GetWebClient());
NSString* pluginNotSupportedText = base::SysUTF16ToNSString(
web::GetWebClient()->GetPluginNotSupportedText());
NSString* placeholderCall = [NSString stringWithFormat:
@"__gCrWeb.plugin.addPluginPlaceholders(%@);",
EscapedQuotedString(pluginNotSupportedText)];
return [baseContent stringByAppendingString:placeholderCall];
}
@end
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_JS_CRW_JS_WINDOW_ID_MANAGER_H_
#define IOS_WEB_WEB_STATE_JS_CRW_JS_WINDOW_ID_MANAGER_H_
#import "ios/web/public/web_state/js/crw_js_injection_manager.h"
// Loads the JavaScript file window_id.js which sets __gCrWeb.windowId and
// manages the windowId for messages.
@interface CRWJSWindowIdManager : CRWJSInjectionManager
// A unique window ID is assigned when the script is injected.
@property(nonatomic, copy) NSString* windowId;
@end
#endif // IOS_WEB_WEB_STATE_JS_CRW_JS_WINDOW_ID_MANAGER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/web_state/js/crw_js_window_id_manager.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "crypto/random.h"
namespace {
// Number of random bytes in unique key for window ID. The length of the
// window ID will be twice this number, as it is hexadecimal encoded.
const NSInteger kUniqueKeyLength = 16;
} // namespace
@interface CRWJSWindowIdManager () {
base::scoped_nsobject<NSString> _windowId;
}
// Returns a string of randomized ASCII characters.
- (NSString*)generateUniqueKey;
@end
@implementation CRWJSWindowIdManager
- (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver {
self = [super initWithReceiver:receiver];
if (self) {
_windowId.reset([[self generateUniqueKey] retain]);
}
return self;
}
- (NSString*)windowId {
return _windowId;
}
- (void)setWindowId:(NSString*)value {
_windowId.reset([value copy]);
}
#pragma mark ProtectedMethods
- (NSString*)scriptPath {
return @"window_id";
}
- (NSString*)presenceBeacon {
return @"__gCrWeb.windowIdObject";
}
// It is important to recreate the injection content on every injection, because
// it cotains the randomly-generated page ID used for security checks.
- (NSString*)injectionContent {
_windowId.reset([[self generateUniqueKey] retain]);
NSString* script = [super injectionContent];
return [script stringByReplacingOccurrencesOfString:@"$(WINDOW_ID)"
withString:_windowId];
}
#pragma mark - Private
- (NSString*)generateUniqueKey {
char randomBytes[kUniqueKeyLength];
crypto::RandBytes(randomBytes, kUniqueKeyLength);
return
base::SysUTF8ToNSString(base::HexEncode(randomBytes, kUniqueKeyLength));
}
@end
...@@ -42,8 +42,14 @@ new function() { ...@@ -42,8 +42,14 @@ new function() {
*/ */
var touchMargin_ = 25; var touchMargin_ = 25;
__gCrWeb['innerSizeAsString'] = function() { __gCrWeb['getPageWidth'] = function() {
return window.innerWidth + '/' + window.innerHeight; var documentElement = document.documentElement;
var documentBody = document.body;
return Math.max(documentElement.clientWidth,
documentElement.scrollWidth,
documentElement.offsetWidth,
documentBody.scrollWidth,
documentBody.offsetWidth);
}; };
// Implementation of document.elementFromPoint that is working for iOS4 and // Implementation of document.elementFromPoint that is working for iOS4 and
......
...@@ -30,6 +30,20 @@ void WebStateObserverBridge::NavigationItemCommitted( ...@@ -30,6 +30,20 @@ void WebStateObserverBridge::NavigationItemCommitted(
} }
} }
void WebStateObserverBridge::DidStartLoading() {
SEL selector = @selector(webStateDidStartLoading:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webStateDidStartLoading:web_state()];
}
}
void WebStateObserverBridge::DidStopLoading() {
SEL selector = @selector(webStateDidStopLoading:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webStateDidStopLoading:web_state()];
}
}
void WebStateObserverBridge::PageLoaded( void WebStateObserverBridge::PageLoaded(
web::PageLoadCompletionStatus load_completion_status) { web::PageLoadCompletionStatus load_completion_status) {
SEL selector = @selector(webStateDidLoadPage:); SEL selector = @selector(webStateDidLoadPage:);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment