Commit 5bbe669d authored by michaeldo's avatar michaeldo Committed by Commit bot

Move _changingHistoryState to superclass.

Move _changingHistoryState boolean to CRWWebController.

BUG= 579697

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

Cr-Commit-Position: refs/heads/master@{#384304}
parent f548411f
......@@ -90,10 +90,6 @@ enum WebViewDocumentType {
// Cancels any load in progress in the web view.
- (void)abortWebLoad;
// Returns selector to handle JavaScript message with command property
// |command|. Subclasses may override to handle class-specific messages.
- (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command;
// Sets zoom scale value for webview scroll view from |zoomState|.
- (void)applyWebViewScrollZoomScaleFromZoomState:
(const web::PageZoomState&)zoomState;
......@@ -184,6 +180,10 @@ enum WebViewDocumentType {
// loaded.
@property(nonatomic, readwrite) BOOL userInteractionRegistered;
// Whether the web page is currently performing window.history.pushState or
// window.history.replaceState
@property(nonatomic, readonly) BOOL changingHistoryState;
// Returns the current window id.
@property(nonatomic, readonly) NSString* windowId;
......
......@@ -258,6 +258,11 @@ void CancelTouches(UIGestureRecognizer* gesture_recognizer) {
// if the next load request is for that URL, it should be treated as a
// reconstruction that should use cache aggressively.
GURL _expectedReconstructionURL;
// Whether the web page is currently performing window.history.pushState or
// window.history.replaceState
// Set to YES on window.history.willChangeState message. To NO on
// window.history.didPushState or window.history.didReplaceState.
BOOL _changingHistoryState;
scoped_ptr<web::NewWindowInfo> _externalRequest;
......@@ -1899,6 +1904,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
return _isHalted;
}
- (BOOL)changingHistoryState {
return _changingHistoryState;
}
- (web::ReferrerPolicy)referrerPolicyFromString:(const std::string&)policy {
// TODO(stuartmorgan): Remove this temporary bridge to the helper function
// once the referrer handling moves into the subclasses.
......@@ -2397,22 +2406,15 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
- (BOOL)handleWindowHistoryWillChangeStateMessage:(base::DictionaryValue*)unused
context:(NSDictionary*)unusedContext {
// This dummy handler is a workaround for crbug.com/490673. Issue was
// happening when two sequential calls of window.history.pushState were
// performed by the page. In that case state was changed twice before
// first change was reported to embedder (and first URL change was reported
// incorrectly).
// Using dummy handler for window.history.willChangeState message holds
// second state change until the first change is reported, because messages
// are queued. This is essentially a sleep, and not the real fix of the
// problem. TODO(eugenebut): refactor handleWindowHistoryDidPushStateMessage:
// to avoid this "sleep".
_changingHistoryState = YES;
return YES;
}
- (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context {
DCHECK(_changingHistoryState);
_changingHistoryState = NO;
// If there is a pending entry, a new navigation has been registered but
// hasn't begun loading. Since the pushState message is coming from the
// previous page, ignore it and allow the previously registered navigation to
......@@ -2494,6 +2496,9 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
- (BOOL)handleWindowHistoryDidReplaceStateMessage:
(base::DictionaryValue*)message
context:(NSDictionary*)context {
DCHECK(_changingHistoryState);
_changingHistoryState = NO;
std::string pageURL;
std::string baseURL;
if (!message->GetString("pageUrl", &pageURL) ||
......
......@@ -196,12 +196,6 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
// Object for loading POST requests with body.
base::scoped_nsobject<CRWJSPOSTRequestLoader> _POSTRequestLoader;
// Whether the web page is currently performing window.history.pushState or
// window.history.replaceState
// Set to YES on window.history.willChangeState message. To NO on
// window.history.didPushState or window.history.didReplaceState.
BOOL _changingHistoryState;
// CRWWebUIManager object for loading WebUI pages.
base::scoped_nsobject<CRWWebUIManager> _webUIManager;
......@@ -1196,7 +1190,7 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
// registering a load request logically comes before updating the document
// URL, but also must come first since it uses state that is reset on URL
// changes.
if (!_changingHistoryState) {
if (!self.changingHistoryState) {
// If this wasn't a previously-expected load (e.g., certain back/forward
// navigations), register the load request.
if (![self isLoadRequestPendingForURL:newURL])
......@@ -1205,7 +1199,7 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
[self setDocumentURL:newURL];
if (!_changingHistoryState) {
if (!self.changingHistoryState) {
[self didStartLoadingURL:_documentURL updateHistory:YES];
[self updateSSLStatusForCurrentNavigationItem];
[self didFinishNavigation];
......@@ -1270,25 +1264,6 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
return NO;
}
- (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command {
static std::map<std::string, SEL>* handlers = nullptr;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
handlers = new std::map<std::string, SEL>();
(*handlers)["window.history.didPushState"] =
@selector(handleWindowHistoryDidPushStateMessage:context:);
(*handlers)["window.history.didReplaceState"] =
@selector(handleWindowHistoryDidReplaceStateMessage:context:);
(*handlers)["window.history.willChangeState"] =
@selector(handleWindowHistoryWillChangeStateMessage:context:);
});
DCHECK(handlers);
auto iter = handlers->find(command);
return iter != handlers->end()
? iter->second
: [super selectorToHandleJavaScriptCommand:command];
}
- (BOOL)shouldAbortLoadForCancelledError:(NSError*)error {
DCHECK_EQ(error.code, NSURLErrorCancelled);
// Do not abort the load if it is for an app specific URL, as such errors
......@@ -1352,33 +1327,6 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
stringResultHandler:nil];
}
#pragma mark -
#pragma mark JavaScript message handlers
- (BOOL)handleWindowHistoryWillChangeStateMessage:
(base::DictionaryValue*)message
context:(NSDictionary*)context {
_changingHistoryState = YES;
return
[super handleWindowHistoryWillChangeStateMessage:message context:context];
}
- (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context {
DCHECK(_changingHistoryState);
_changingHistoryState = NO;
return [super handleWindowHistoryDidPushStateMessage:message context:context];
}
- (BOOL)handleWindowHistoryDidReplaceStateMessage:
(base::DictionaryValue*)message
context:(NSDictionary*)context {
DCHECK(_changingHistoryState);
_changingHistoryState = NO;
return [super handleWindowHistoryDidReplaceStateMessage:message
context:context];
}
#pragma mark -
#pragma mark WebUI
......
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