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

Side by Side Diff: components/dom_distiller/ios/distiller_page_ios.mm

Issue 2932353002: [ObjC ARC] Converts components/dom_distiller/ios:ios to ARC. (Closed)
Patch Set: Created 3 years, 6 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 | « components/dom_distiller/ios/distiller_page_factory_ios.mm ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/dom_distiller/ios/distiller_page_ios.h" 5 #include "components/dom_distiller/ios/distiller_page_ios.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/sys_string_conversions.h" 16 #include "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/public/browser_state.h" 19 #include "ios/web/public/browser_state.h"
20 #import "ios/web/public/navigation_manager.h" 20 #import "ios/web/public/navigation_manager.h"
21 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" 21 #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
22 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 22 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
23 #import "ios/web/public/web_state/web_state.h" 23 #import "ios/web/public/web_state/web_state.h"
24 #include "ios/web/public/web_state/web_state_observer.h" 24 #include "ios/web/public/web_state/web_state_observer.h"
25 25
26 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support."
28 #endif
29
26 namespace { 30 namespace {
27 31
28 // This is duplicated here from ios/web/web_state/ui/web_view_js_utils.mm in 32 // This is duplicated here from ios/web/web_state/ui/web_view_js_utils.mm in
29 // order to handle numbers. The dom distiller proto expects integers and the 33 // order to handle numbers. The dom distiller proto expects integers and the
30 // generated JSON deserializer does not accept doubles in the place of ints. 34 // generated JSON deserializer does not accept doubles in the place of ints.
31 // However WKWebView only returns "numbers." However, here the proto expects 35 // However WKWebView only returns "numbers." However, here the proto expects
32 // integers and doubles, which is done by checking if the number has a fraction 36 // integers and doubles, which is done by checking if the number has a fraction
33 // or not; since this is a hacky method it's isolated to this file so as to 37 // or not; since this is a hacky method it's isolated to this file so as to
34 // limit the risk of broken JS calls. 38 // limit the risk of broken JS calls.
35 39
36 int const kMaximumParsingRecursionDepth = 6; 40 int const kMaximumParsingRecursionDepth = 6;
37 // Converts result of WKWebView script evaluation to base::Value, parsing 41 // Converts result of WKWebView script evaluation to base::Value, parsing
38 // |wk_result| up to a depth of |max_depth|. 42 // |wk_result| up to a depth of |max_depth|.
39 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result, 43 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result,
40 int max_depth) { 44 int max_depth) {
41 if (!wk_result) 45 if (!wk_result)
42 return nullptr; 46 return nullptr;
43 47
44 std::unique_ptr<base::Value> result; 48 std::unique_ptr<base::Value> result;
45 49
46 if (max_depth < 0) { 50 if (max_depth < 0) {
47 DLOG(WARNING) << "JS maximum recursion depth exceeded."; 51 DLOG(WARNING) << "JS maximum recursion depth exceeded.";
48 return result; 52 return result;
49 } 53 }
50 54
51 CFTypeID result_type = CFGetTypeID(wk_result); 55 CFTypeID result_type = CFGetTypeID(reinterpret_cast<const void*>(wk_result));
noyau (Ping after 24h) 2017/06/13 08:40:44 reinterpret_cast<CFTypeRef> maybe?
marq (ping after 24h) 2017/06/13 13:10:47 Good call, done.
52 if (result_type == CFStringGetTypeID()) { 56 if (result_type == CFStringGetTypeID()) {
53 result.reset(new base::Value(base::SysNSStringToUTF16(wk_result))); 57 result.reset(new base::Value(base::SysNSStringToUTF16(wk_result)));
54 DCHECK(result->IsType(base::Value::Type::STRING)); 58 DCHECK(result->IsType(base::Value::Type::STRING));
55 } else if (result_type == CFNumberGetTypeID()) { 59 } else if (result_type == CFNumberGetTypeID()) {
56 // Different implementation is here. 60 // Different implementation is here.
57 if ([wk_result intValue] != [wk_result doubleValue]) { 61 if ([wk_result intValue] != [wk_result doubleValue]) {
58 result.reset(new base::Value([wk_result doubleValue])); 62 result.reset(new base::Value([wk_result doubleValue]));
59 DCHECK(result->IsType(base::Value::Type::DOUBLE)); 63 DCHECK(result->IsType(base::Value::Type::DOUBLE));
60 } else { 64 } else {
61 result.reset(new base::Value([wk_result intValue])); 65 result.reset(new base::Value([wk_result intValue]));
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 242 }
239 OnDistillationDone(url_, resultValue.get()); 243 OnDistillationDone(url_, resultValue.get());
240 } 244 }
241 245
242 std::unique_ptr<base::Value> DistillerPageIOS::ValueResultFromScriptResult( 246 std::unique_ptr<base::Value> DistillerPageIOS::ValueResultFromScriptResult(
243 id wk_result) { 247 id wk_result) {
244 return ::ValueResultFromScriptResult(wk_result, 248 return ::ValueResultFromScriptResult(wk_result,
245 kMaximumParsingRecursionDepth); 249 kMaximumParsingRecursionDepth);
246 } 250 }
247 } // namespace dom_distiller 251 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/ios/distiller_page_factory_ios.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698