Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: ios/chrome/browser/ui/static_content/static_html_view_controller.mm

Issue 2597133002: Do not navigate on loading iframes in StaticHTMLViewController. (Closed)
Patch Set: feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/ui/static_content/static_html_view_controller.h" 5 #include "ios/chrome/browser/ui/static_content/static_html_view_controller.h"
6 6
7 #include <WebKit/WebKit.h> 7 #include <WebKit/WebKit.h>
8 8
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 id<CRWNativeContentDelegate> delegate_; // weak 77 id<CRWNativeContentDelegate> delegate_; // weak
78 78
79 // The loader to navigate from the page. 79 // The loader to navigate from the page.
80 id<UrlLoader> loader_; // weak 80 id<UrlLoader> loader_; // weak
81 } 81 }
82 82
83 // Returns the URL of the static page to display. 83 // Returns the URL of the static page to display.
84 - (NSURL*)resourceURL; 84 - (NSURL*)resourceURL;
85 // Ensures that webView_ has been created, creating it if necessary. 85 // Ensures that webView_ has been created, creating it if necessary.
86 - (void)ensureWebViewCreated; 86 - (void)ensureWebViewCreated;
87 // Determines if the page load should begin based on the current |resourceURL|. 87 // Determines if the page load should begin based on the current |resourceURL|
88 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request; 88 // and if the request is issued by the main frame (|fromMainFrame|).
89 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request
90 fromMainFrame:(BOOL)fromMainFrame;
89 @end 91 @end
90 92
91 @implementation StaticHtmlViewController 93 @implementation StaticHtmlViewController
92 94
93 - (instancetype)initWithResource:(NSString*)resource 95 - (instancetype)initWithResource:(NSString*)resource
94 browserState:(web::BrowserState*)browserState { 96 browserState:(web::BrowserState*)browserState {
95 DCHECK(resource); 97 DCHECK(resource);
96 DCHECK(browserState); 98 DCHECK(browserState);
97 if ((self = [super init])) { 99 if ((self = [super init])) {
98 resource_.reset([resource copy]); 100 resource_.reset([resource copy]);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 [[self scrollView] setScrollEnabled:enabled]; 194 [[self scrollView] setScrollEnabled:enabled];
193 } 195 }
194 196
195 #pragma mark - 197 #pragma mark -
196 #pragma mark WKNavigationDelegate implementation 198 #pragma mark WKNavigationDelegate implementation
197 199
198 - (void)webView:(WKWebView*)webView 200 - (void)webView:(WKWebView*)webView
199 decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction 201 decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction
200 decisionHandler: 202 decisionHandler:
201 (void (^)(WKNavigationActionPolicy))decisionHandler { 203 (void (^)(WKNavigationActionPolicy))decisionHandler {
202 decisionHandler([self shouldStartLoadWithRequest:navigationAction.request] 204 decisionHandler(
203 ? WKNavigationActionPolicyAllow 205 [self
204 : WKNavigationActionPolicyCancel); 206 shouldStartLoadWithRequest:navigationAction.request
207 fromMainFrame:[navigationAction.sourceFrame isMainFrame]]
208 ? WKNavigationActionPolicyAllow
209 : WKNavigationActionPolicyCancel);
205 } 210 }
206 211
207 #pragma mark - 212 #pragma mark -
208 #pragma mark KVO callback 213 #pragma mark KVO callback
209 214
210 - (void)observeValueForKeyPath:(NSString*)keyPath 215 - (void)observeValueForKeyPath:(NSString*)keyPath
211 ofObject:(id)object 216 ofObject:(id)object
212 change:(NSDictionary*)change 217 change:(NSDictionary*)change
213 context:(void*)context { 218 context:(void*)context {
214 DCHECK([keyPath isEqualToString:@"title"]); 219 DCHECK([keyPath isEqualToString:@"title"]);
215 if ([delegate_ respondsToSelector:@selector(nativeContent:titleDidChange:)]) { 220 if ([delegate_ respondsToSelector:@selector(nativeContent:titleDidChange:)]) {
216 // WKWebView's |title| changes to nil when its web process crashes. 221 // WKWebView's |title| changes to nil when its web process crashes.
217 if ([webView_ title]) 222 if ([webView_ title])
218 [delegate_ nativeContent:self titleDidChange:[webView_ title]]; 223 [delegate_ nativeContent:self titleDidChange:[webView_ title]];
219 } 224 }
220 } 225 }
221 226
222 #pragma mark - 227 #pragma mark -
223 #pragma mark Private 228 #pragma mark Private
224 229
225 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request { 230 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request
231 fromMainFrame:(BOOL)fromMainFrame {
226 // Only allow displaying the URL which correspond to the authorized resource. 232 // Only allow displaying the URL which correspond to the authorized resource.
227 if ([[request URL] isEqual:[self resourceURL]]) 233 if ([[request URL] isEqual:[self resourceURL]])
228 return YES; 234 return YES;
229 235
230 // All other URLs will be loaded by our UrlLoader if we have one. 236 // All other navigation URLs will be loaded by our UrlLoader if one exists and
231 if (loader_) { 237 // if they are issued by the main frame.
238 if (loader_ && fromMainFrame) {
232 dispatch_async(dispatch_get_main_queue(), ^{ 239 dispatch_async(dispatch_get_main_queue(), ^{
233 [loader_ loadURL:net::GURLWithNSURL([request URL]) 240 [loader_ loadURL:net::GURLWithNSURL([request URL])
234 referrer:referrer_ 241 referrer:referrer_
235 transition:ui::PAGE_TRANSITION_LINK 242 transition:ui::PAGE_TRANSITION_LINK
236 rendererInitiated:YES]; 243 rendererInitiated:YES];
237 }); 244 });
238 } 245 }
239 return NO; 246 return NO;
240 } 247 }
241 248
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 allowingReadAccessToURL:resourcesRootDirectory_]; 294 allowingReadAccessToURL:resourcesRootDirectory_];
288 } else { 295 } else {
289 NSURL* resourceURL = [self resourceURL]; 296 NSURL* resourceURL = [self resourceURL];
290 [generator_ generateHtml:^(NSString* HTML) { 297 [generator_ generateHtml:^(NSString* HTML) {
291 [webView loadHTMLString:HTML baseURL:resourceURL]; 298 [webView loadHTMLString:HTML baseURL:resourceURL];
292 }]; 299 }];
293 } 300 }
294 } 301 }
295 302
296 @end 303 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698