Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/web/webui/crw_web_ui_manager.h" | 5 #import "ios/web/webui/crw_web_ui_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| 11 #import "base/mac/bind_objc_block.h" | 11 #import "base/mac/bind_objc_block.h" |
| 12 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #import "base/strings/sys_string_conversions.h" | 16 #import "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "ios/web/grit/ios_web_resources.h" | 19 #include "ios/web/grit/ios_web_resources.h" |
| 20 #import "ios/web/net/request_group_util.h" | 20 #import "ios/web/net/request_group_util.h" |
|
Eugene But (OOO till 7-30)
2017/01/19 19:05:55
nit: Do we still need this include?
sdefresne
2017/01/20 11:31:28
Removed.
| |
| 21 #include "ios/web/public/browser_state.h" | 21 #include "ios/web/public/browser_state.h" |
| 22 #import "ios/web/public/web_client.h" | 22 #import "ios/web/public/web_client.h" |
| 23 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 23 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 24 #import "ios/web/web_state/web_state_impl.h" | 24 #import "ios/web/web_state/web_state_impl.h" |
| 25 #import "ios/web/webui/crw_web_ui_page_builder.h" | 25 #import "ios/web/webui/crw_web_ui_page_builder.h" |
| 26 #include "ios/web/webui/mojo_js_constants.h" | 26 #include "ios/web/webui/mojo_js_constants.h" |
| 27 #import "ios/web/webui/url_fetcher_block_adapter.h" | 27 #import "ios/web/webui/url_fetcher_block_adapter.h" |
| 28 #include "mojo/public/js/constants.h" | 28 #include "mojo/public/js/constants.h" |
| 29 #import "net/base/mac/url_conversions.h" | 29 #import "net/base/mac/url_conversions.h" |
| 30 | 30 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 106 |
| 107 #pragma mark - CRWWebStateObserver Methods | 107 #pragma mark - CRWWebStateObserver Methods |
| 108 | 108 |
| 109 - (void)webState:(web::WebState*)webState | 109 - (void)webState:(web::WebState*)webState |
| 110 didStartProvisionalNavigationForURL:(const GURL&)URL { | 110 didStartProvisionalNavigationForURL:(const GURL&)URL { |
| 111 DCHECK(webState == _webState); | 111 DCHECK(webState == _webState); |
| 112 // If URL is not an application specific URL, ignore the navigation. | 112 // If URL is not an application specific URL, ignore the navigation. |
| 113 if (!web::GetWebClient()->IsAppSpecificURL(URL)) | 113 if (!web::GetWebClient()->IsAppSpecificURL(URL)) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 GURL navigationURL(URL); | 116 // Copy |URL| as it is passed by reference which does not work correctly |
| 117 // Add request group ID to the URL, if not present. Request group ID may | 117 // with blocks (if the object is destroyed the block will have a dangling |
| 118 // already be added if restoring state to a WebUI page. | 118 // reference). |
| 119 GURL requestURL = | 119 GURL copyURL(URL); |
| 120 web::ExtractRequestGroupIDFromURL(net::NSURLWithGURL(URL)) | |
| 121 ? URL | |
| 122 : net::GURLWithNSURL(web::AddRequestGroupIDToURL( | |
| 123 net::NSURLWithGURL(URL), _webState->GetRequestGroupID())); | |
| 124 base::WeakNSObject<CRWWebUIManager> weakSelf(self); | 120 base::WeakNSObject<CRWWebUIManager> weakSelf(self); |
| 125 [self loadWebUIPageForURL:requestURL | 121 [self loadWebUIPageForURL:copyURL |
| 126 completionHandler:^(NSString* HTML) { | 122 completionHandler:^(NSString* HTML) { |
| 127 web::WebStateImpl* webState = [weakSelf webState]; | 123 web::WebStateImpl* webState = [weakSelf webState]; |
| 128 if (webState) { | 124 if (webState) { |
| 129 webState->LoadWebUIHtml(base::SysNSStringToUTF16(HTML), | 125 webState->LoadWebUIHtml(base::SysNSStringToUTF16(HTML), copyURL); |
| 130 navigationURL); | |
| 131 } | 126 } |
| 132 }]; | 127 }]; |
| 133 } | 128 } |
| 134 | 129 |
| 135 - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { | 130 - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { |
| 136 DCHECK_EQ(webState, _webState); | 131 DCHECK_EQ(webState, _webState); |
| 137 // All WebUI pages are HTML based. | 132 // All WebUI pages are HTML based. |
| 138 _webState->SetContentsMimeType("text/html"); | 133 _webState->SetContentsMimeType("text/html"); |
| 139 } | 134 } |
| 140 | 135 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 #pragma mark - Testing-Only Methods | 302 #pragma mark - Testing-Only Methods |
| 308 | 303 |
| 309 - (std::unique_ptr<web::URLFetcherBlockAdapter>) | 304 - (std::unique_ptr<web::URLFetcherBlockAdapter>) |
| 310 fetcherForURL:(const GURL&)URL | 305 fetcherForURL:(const GURL&)URL |
| 311 completionHandler:(web::URLFetcherBlockAdapterCompletion)handler { | 306 completionHandler:(web::URLFetcherBlockAdapterCompletion)handler { |
| 312 return base::MakeUnique<web::URLFetcherBlockAdapter>( | 307 return base::MakeUnique<web::URLFetcherBlockAdapter>( |
| 313 URL, _webState->GetBrowserState()->GetRequestContext(), handler); | 308 URL, _webState->GetBrowserState()->GetRequestContext(), handler); |
| 314 } | 309 } |
| 315 | 310 |
| 316 @end | 311 @end |
| OLD | NEW |