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/web/webui/crw_web_ui_manager.mm

Issue 2260023004: [ARC] [Split this CL] Convert ios/web/webui to ARC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-web-net
Patch Set: Created 4 years, 4 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 | « ios/web/BUILD.gn ('k') | ios/web/webui/crw_web_ui_page_builder.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/json/string_escape.h" 7 #include "base/json/string_escape.h"
8 #include "base/mac/bind_objc_block.h" 8 #include "base/mac/bind_objc_block.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #import "base/strings/sys_string_conversions.h" 13 #import "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "ios/web/grit/ios_web_resources.h" 16 #include "ios/web/grit/ios_web_resources.h"
17 #import "ios/web/net/request_group_util.h" 17 #import "ios/web/net/request_group_util.h"
18 #include "ios/web/public/browser_state.h" 18 #include "ios/web/public/browser_state.h"
19 #include "ios/web/public/web_client.h" 19 #include "ios/web/public/web_client.h"
20 #import "ios/web/public/web_state/web_state_observer_bridge.h" 20 #import "ios/web/public/web_state/web_state_observer_bridge.h"
21 #include "ios/web/web_state/web_state_impl.h" 21 #include "ios/web/web_state/web_state_impl.h"
22 #import "ios/web/webui/crw_web_ui_page_builder.h" 22 #import "ios/web/webui/crw_web_ui_page_builder.h"
23 #include "ios/web/webui/mojo_js_constants.h" 23 #include "ios/web/webui/mojo_js_constants.h"
24 #include "ios/web/webui/url_fetcher_block_adapter.h" 24 #include "ios/web/webui/url_fetcher_block_adapter.h"
25 #include "mojo/public/js/constants.h" 25 #include "mojo/public/js/constants.h"
26 #import "net/base/mac/url_conversions.h" 26 #import "net/base/mac/url_conversions.h"
27 27
28 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support."
30 #endif
31
28 namespace { 32 namespace {
29 // Prefix for history.requestFavicon JavaScript message. 33 // Prefix for history.requestFavicon JavaScript message.
30 const char kScriptCommandPrefix[] = "webui"; 34 const char kScriptCommandPrefix[] = "webui";
31 } 35 }
32 36
33 @interface CRWWebUIManager () <CRWWebUIPageBuilderDelegate> 37 @interface CRWWebUIManager () <CRWWebUIPageBuilderDelegate>
34 38
35 // Current web state. 39 // Current web state.
36 @property(nonatomic, readonly) web::WebStateImpl* webState; 40 @property(nonatomic, readonly) web::WebStateImpl* webState;
37 41
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 ^bool(const base::DictionaryValue& message, const GURL&, bool) { 95 ^bool(const base::DictionaryValue& message, const GURL&, bool) {
92 return [weakSelf handleWebUIJSMessage:message]; 96 return [weakSelf handleWebUIJSMessage:message];
93 }), 97 }),
94 kScriptCommandPrefix); 98 kScriptCommandPrefix);
95 } 99 }
96 return self; 100 return self;
97 } 101 }
98 102
99 - (void)dealloc { 103 - (void)dealloc {
100 [self resetWebState]; 104 [self resetWebState];
101 [super dealloc];
102 } 105 }
103 106
104 #pragma mark - CRWWebStateObserver Methods 107 #pragma mark - CRWWebStateObserver Methods
105 108
106 - (void)webState:(web::WebState*)webState 109 - (void)webState:(web::WebState*)webState
107 didStartProvisionalNavigationForURL:(const GURL&)URL { 110 didStartProvisionalNavigationForURL:(const GURL&)URL {
108 DCHECK(webState == _webState); 111 DCHECK(webState == _webState);
109 // If URL is not an application specific URL, ignore the navigation. 112 // If URL is not an application specific URL, ignore the navigation.
110 if (!web::GetWebClient()->IsAppSpecificURL(URL)) 113 if (!web::GetWebClient()->IsAppSpecificURL(URL))
111 return; 114 return;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 std::string favicon; 210 std::string favicon;
208 if (!arguments->GetString(0, &favicon)) { 211 if (!arguments->GetString(0, &favicon)) {
209 DLOG(WARNING) << "JS message parameter not found: Favicon URL"; 212 DLOG(WARNING) << "JS message parameter not found: Favicon URL";
210 return NO; 213 return NO;
211 } 214 }
212 GURL faviconURL(favicon); 215 GURL faviconURL(favicon);
213 DCHECK(faviconURL.is_valid()); 216 DCHECK(faviconURL.is_valid());
214 // Retrieve favicon resource and set favicon background image via JavaScript. 217 // Retrieve favicon resource and set favicon background image via JavaScript.
215 base::WeakNSObject<CRWWebUIManager> weakSelf(self); 218 base::WeakNSObject<CRWWebUIManager> weakSelf(self);
216 void (^faviconHandler)(NSData*) = ^void(NSData* data) { 219 void (^faviconHandler)(NSData*) = ^void(NSData* data) {
217 base::scoped_nsobject<CRWWebUIManager> strongSelf([weakSelf retain]); 220 base::scoped_nsobject<CRWWebUIManager> strongSelf(weakSelf);
218 if (!strongSelf) 221 if (!strongSelf)
219 return; 222 return;
220 NSString* base64EncodedResource = [data base64EncodedStringWithOptions:0]; 223 NSString* base64EncodedResource = [data base64EncodedStringWithOptions:0];
221 NSString* dataURLString = [NSString 224 NSString* dataURLString = [NSString
222 stringWithFormat:@"data:image/png;base64,%@", base64EncodedResource]; 225 stringWithFormat:@"data:image/png;base64,%@", base64EncodedResource];
223 NSString* faviconURLString = base::SysUTF8ToNSString(faviconURL.spec()); 226 NSString* faviconURLString = base::SysUTF8ToNSString(faviconURL.spec());
224 NSString* script = 227 NSString* script =
225 [NSString stringWithFormat:@"chrome.setFaviconBackground('%@', '%@');", 228 [NSString stringWithFormat:@"chrome.setFaviconBackground('%@', '%@');",
226 faviconURLString, dataURLString]; 229 faviconURLString, dataURLString];
227 [strongSelf webState]->ExecuteJavaScript(base::SysNSStringToUTF16(script)); 230 [strongSelf webState]->ExecuteJavaScript(base::SysNSStringToUTF16(script));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 332
330 - (std::unique_ptr<web::URLFetcherBlockAdapter>) 333 - (std::unique_ptr<web::URLFetcherBlockAdapter>)
331 fetcherForURL:(const GURL&)URL 334 fetcherForURL:(const GURL&)URL
332 completionHandler:(web::URLFetcherBlockAdapterCompletion)handler { 335 completionHandler:(web::URLFetcherBlockAdapterCompletion)handler {
333 return std::unique_ptr<web::URLFetcherBlockAdapter>( 336 return std::unique_ptr<web::URLFetcherBlockAdapter>(
334 new web::URLFetcherBlockAdapter( 337 new web::URLFetcherBlockAdapter(
335 URL, _webState->GetBrowserState()->GetRequestContext(), handler)); 338 URL, _webState->GetBrowserState()->GetRequestContext(), handler));
336 } 339 }
337 340
338 @end 341 @end
OLDNEW
« no previous file with comments | « ios/web/BUILD.gn ('k') | ios/web/webui/crw_web_ui_page_builder.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698