0

Inject windowID when web view content is an image.

The system context menu is now always blocked, so we must use our own
to allow interaction with image content. We must inject the windowID
because our context menu implementation relies on injected javascript.

Bug: 777313
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I0c0c5515c3fe99e5f7db6d963c0cdc1ec84940ac
Reviewed-on: https://chromium-review.googlesource.com/735121
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#511214}
This commit is contained in:
Mike Dougherty
2017-10-24 18:34:43 +00:00
committed by Commit Bot
parent 659b019887
commit c47b1f1313

@ -677,6 +677,8 @@ registerLoadRequestForURL:(const GURL&)URL
- (void)forgetNullWKNavigation:(WKNavigation*)navigation;
- (BOOL)isLoaded;
// Returns YES if the current live view is a web view with an image MIME type.
- (BOOL)contentIsImage;
// Extracts the current page's viewport tag information and calls |completion|.
// If the page has changed before the viewport tag is successfully extracted,
// |completion| is called with nullptr.
@ -1965,6 +1967,15 @@ registerLoadRequestForURL:(const GURL&)requestURL
return _loadPhase == web::PAGE_LOADED;
}
- (BOOL)contentIsImage {
if (!_webView)
return NO;
const std::string image = "image";
std::string MIMEType = self.webState->GetContentsMimeType();
return MIMEType.compare(0, image.length(), image) == 0;
}
- (void)didFinishNavigation:(WKNavigation*)navigation {
// This can be called at multiple times after the document has loaded. Do
// nothing if the document has already loaded.
@ -4598,7 +4609,8 @@ registerLoadRequestForURL:(const GURL&)requestURL
// This point should closely approximate the document object change, so reset
// the list of injected scripts to those that are automatically injected.
_injectedScriptManagers = [[NSMutableSet alloc] init];
if ([self contentIsHTML] || self.webState->GetContentsMimeType().empty()) {
if ([self contentIsHTML] || [self contentIsImage] ||
self.webState->GetContentsMimeType().empty()) {
// In unit tests MIME type will be empty, because loadHTML:forURL: does not
// notify web view delegate about received response, so web controller does
// not get a chance to properly update MIME type.