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 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" | 5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" |
6 | 6 |
7 #include <vector> | |
8 | |
9 #include "base/strings/string_util.h" | |
7 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 10 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
8 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" | 11 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" |
12 #include "chrome/common/chrome_constants.h" | |
13 #include "chrome/common/render_messages.h" | |
9 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
10 | 15 |
16 namespace { | |
17 | |
18 const char kMetaViewportTagName[] = "viewport"; | |
gone
2015/05/27 22:53:35
Should ask Paul Kinlan about formatting. Curious
dominickn (DO NOT USE)
2015/06/05 07:42:59
Ben found some code in the compositor which seems
| |
19 const char kMetaViewportWidthDevice[] = "width=device-width"; | |
20 const char kMetaViewportInitialScaleInt[] = "initial-scale=1"; | |
21 const char kMetaViewportInitialScaleFloat[] = "initial-scale=1.0"; | |
22 | |
23 } // anonymous namespace | |
24 | |
11 namespace banners { | 25 namespace banners { |
12 | 26 |
13 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( | 27 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( |
14 content::WebContents* web_contents, | 28 content::WebContents* web_contents, |
15 base::WeakPtr<Delegate> weak_delegate, | 29 base::WeakPtr<Delegate> weak_delegate, |
16 int ideal_icon_size) | 30 int ideal_icon_size) |
17 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { | 31 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { |
18 } | 32 } |
19 | 33 |
20 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { | 34 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { |
21 } | 35 } |
22 | 36 |
23 std::string AppBannerDataFetcherAndroid::GetBannerType() { | 37 std::string AppBannerDataFetcherAndroid::GetBannerType() { |
24 return native_app_data_.is_null() | 38 return native_app_data_.is_null() |
25 ? AppBannerDataFetcher::GetBannerType() : "android"; | 39 ? AppBannerDataFetcher::GetBannerType() : "android"; |
26 } | 40 } |
27 | 41 |
28 bool AppBannerDataFetcherAndroid::ContinueFetching( | 42 bool AppBannerDataFetcherAndroid::ContinueFetching( |
29 const base::string16& app_title, | 43 const base::string16& app_title, |
30 const std::string& app_package, | 44 const std::string& app_package, |
31 base::android::ScopedJavaLocalRef<jobject> app_data, | 45 base::android::ScopedJavaLocalRef<jobject> app_data, |
32 const GURL& image_url) { | 46 const GURL& image_url) { |
33 set_app_title(app_title); | 47 set_app_title(app_title); |
34 native_app_package_ = app_package; | 48 native_app_package_ = app_package; |
35 native_app_data_.Reset(app_data); | 49 native_app_data_.Reset(app_data); |
36 return FetchIcon(image_url); | 50 return FetchIcon(image_url); |
37 } | 51 } |
38 | 52 |
53 bool AppBannerDataFetcherAndroid::OnMessageReceived( | |
54 const IPC::Message& message) { | |
55 bool handled = true; | |
56 IPC_BEGIN_MESSAGE_MAP(AppBannerDataFetcherAndroid, message) | |
57 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, | |
58 OnDidRetrieveMetaTagContent) | |
59 IPC_MESSAGE_UNHANDLED(handled = false) | |
60 IPC_END_MESSAGE_MAP() | |
61 return handled; | |
62 } | |
63 | |
64 void AppBannerDataFetcherAndroid::Start(const GURL& validated_url) { | |
65 validated_url_ = validated_url; | |
66 is_active_ = true; | |
67 is_responsive_ = false; | |
68 | |
69 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), validated_url, | |
70 kMetaViewportTagName)); | |
71 } | |
72 | |
39 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { | 73 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { |
40 return native_app_data_.is_null() | 74 return native_app_data_.is_null() |
41 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; | 75 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; |
42 } | 76 } |
43 | 77 |
44 infobars::InfoBar* AppBannerDataFetcherAndroid::CreateBanner( | 78 infobars::InfoBar* AppBannerDataFetcherAndroid::CreateBanner( |
45 const SkBitmap* icon, | 79 const SkBitmap* icon, |
46 const base::string16& title) { | 80 const base::string16& title) { |
47 content::WebContents* web_contents = GetWebContents(); | 81 content::WebContents* web_contents = GetWebContents(); |
48 DCHECK(web_contents); | 82 DCHECK(web_contents); |
(...skipping 17 matching lines...) Expand all Loading... | |
66 native_app_data_, | 100 native_app_data_, |
67 native_app_package_)); | 101 native_app_package_)); |
68 infobar = new AppBannerInfoBar(delegate.Pass(), native_app_data_); | 102 infobar = new AppBannerInfoBar(delegate.Pass(), native_app_data_); |
69 if (infobar) | 103 if (infobar) |
70 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 104 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
71 } | 105 } |
72 | 106 |
73 return infobar; | 107 return infobar; |
74 } | 108 } |
75 | 109 |
110 void AppBannerDataFetcherAndroid::OnDidRetrieveMetaTagContent( | |
111 bool success, | |
112 const std::string& tag_name, | |
113 const std::string& tag_content, | |
114 const GURL& expected_url) { | |
115 | |
gone
2015/05/27 22:53:35
nit: remove newline
| |
116 if (success && tag_name == kMetaViewportTagName && | |
117 validated_url_ == expected_url && | |
118 tag_content.size() <= chrome::kMaxMetaTagAttributeLength) { | |
119 std::string local_tag_content; | |
120 std::vector<std::string> content_tokens; | |
121 | |
122 base::RemoveChars(tag_content, " ", &local_tag_content); | |
123 base::StringToLowerASCII(&local_tag_content); | |
124 Tokenize(local_tag_content, ",", &content_tokens); | |
125 | |
126 for (auto property : content_tokens) { | |
127 if (property == kMetaViewportWidthDevice || | |
128 property == kMetaViewportInitialScaleInt || | |
129 property == kMetaViewportInitialScaleFloat) { | |
130 is_responsive_ = true; | |
131 break; | |
132 } | |
133 } | |
134 } | |
135 | |
136 AppBannerDataFetcher::Start(validated_url_); | |
137 } | |
138 | |
76 } // namespace banners | 139 } // namespace banners |
OLD | NEW |