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

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: typo Created 3 years, 12 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 the navigation type |type|.
89 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request
90 type:(WKNavigationType)type;
Eugene But (OOO till 7-30) 2016/12/22 16:21:56 nit: s/type/navigationType:
Olivier 2016/12/22 16:42:59 Done.
Eugene But (OOO till 7-30) 2016/12/22 17:37:51 Sorry I meant words before arguments (s/type:/navi
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 shouldStartLoadWithRequest:navigationAction.request
204 : WKNavigationActionPolicyCancel); 206 type:navigationAction.navigationType]
207 ? WKNavigationActionPolicyAllow
208 : WKNavigationActionPolicyCancel);
205 } 209 }
206 210
207 #pragma mark - 211 #pragma mark -
208 #pragma mark KVO callback 212 #pragma mark KVO callback
209 213
210 - (void)observeValueForKeyPath:(NSString*)keyPath 214 - (void)observeValueForKeyPath:(NSString*)keyPath
211 ofObject:(id)object 215 ofObject:(id)object
212 change:(NSDictionary*)change 216 change:(NSDictionary*)change
213 context:(void*)context { 217 context:(void*)context {
214 DCHECK([keyPath isEqualToString:@"title"]); 218 DCHECK([keyPath isEqualToString:@"title"]);
215 if ([delegate_ respondsToSelector:@selector(nativeContent:titleDidChange:)]) { 219 if ([delegate_ respondsToSelector:@selector(nativeContent:titleDidChange:)]) {
216 // WKWebView's |title| changes to nil when its web process crashes. 220 // WKWebView's |title| changes to nil when its web process crashes.
217 if ([webView_ title]) 221 if ([webView_ title])
218 [delegate_ nativeContent:self titleDidChange:[webView_ title]]; 222 [delegate_ nativeContent:self titleDidChange:[webView_ title]];
219 } 223 }
220 } 224 }
221 225
222 #pragma mark - 226 #pragma mark -
223 #pragma mark Private 227 #pragma mark Private
224 228
225 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request { 229 - (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request
230 type:(WKNavigationType)type {
226 // Only allow displaying the URL which correspond to the authorized resource. 231 // Only allow displaying the URL which correspond to the authorized resource.
227 if ([[request URL] isEqual:[self resourceURL]]) 232 if ([[request URL] isEqual:[self resourceURL]])
228 return YES; 233 return YES;
229 234
230 // All other URLs will be loaded by our UrlLoader if we have one. 235 // All other navigation URLs will be loaded by our UrlLoader if we have one.
Eugene But (OOO till 7-30) 2016/12/22 16:21:56 nit: Please avoid "we" in the comments (go/avoidwe
Olivier 2016/12/22 16:42:59 I did not add the we :) Removed.
231 if (loader_) { 236 // If type is |WKNavigationTypeOther|, the URL corresponds to an external
Eugene But (OOO till 7-30) 2016/12/22 16:21:56 What does "external resource mean"? I think WKNavi
Olivier 2016/12/22 16:42:59 Clicking on regular link is WKNavigationTypeLinkAc
237 // resource and should not be loaded at all.
238 if (loader_ && type != WKNavigationTypeOther) {
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