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

Side by Side Diff: chrome/browser/android/banners/app_banner_manager.cc

Issue 893793005: Check if there is a SW controlling the start page for app banner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comment Created 5 years, 10 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
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 "chrome/browser/android/banners/app_banner_manager.h" 5 #include "chrome/browser/android/banners/app_banner_manager.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/threading/worker_pool.h" 12 #include "base/threading/worker_pool.h"
13 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h"
14 #include "chrome/browser/android/banners/app_banner_metrics_ids.h" 14 #include "chrome/browser/android/banners/app_banner_metrics_ids.h"
15 #include "chrome/browser/android/banners/app_banner_utilities.h" 15 #include "chrome/browser/android/banners/app_banner_utilities.h"
16 #include "chrome/browser/android/manifest_icon_selector.h" 16 #include "chrome/browser/android/manifest_icon_selector.h"
17 #include "chrome/browser/android/shortcut_helper.h" 17 #include "chrome/browser/android/shortcut_helper.h"
18 #include "chrome/browser/android/shortcut_info.h" 18 #include "chrome/browser/android/shortcut_info.h"
19 #include "chrome/browser/banners/app_banner_settings_helper.h" 19 #include "chrome/browser/banners/app_banner_settings_helper.h"
20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" 20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
21 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
26 #include "content/public/browser/android/content_view_core.h" 26 #include "content/public/browser/android/content_view_core.h"
27 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/navigation_details.h" 29 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/service_worker_context.h"
32 #include "content/public/browser/storage_partition.h"
29 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/frame_navigate_params.h" 34 #include "content/public/common/frame_navigate_params.h"
31 #include "content/public/common/manifest.h" 35 #include "content/public/common/manifest.h"
32 #include "jni/AppBannerManager_jni.h" 36 #include "jni/AppBannerManager_jni.h"
33 #include "net/base/load_flags.h" 37 #include "net/base/load_flags.h"
34 #include "ui/gfx/android/java_bitmap.h" 38 #include "ui/gfx/android/java_bitmap.h"
35 #include "ui/gfx/screen.h" 39 #include "ui/gfx/screen.h"
36 40
37 using base::android::ConvertJavaStringToUTF8; 41 using base::android::ConvertJavaStringToUTF8;
38 using base::android::ConvertUTF8ToJavaString; 42 using base::android::ConvertUTF8ToJavaString;
39 using base::android::ConvertUTF16ToJavaString; 43 using base::android::ConvertUTF16ToJavaString;
40 44
41 namespace { 45 namespace {
42 const char kBannerTag[] = "google-play-id"; 46 const char kBannerTag[] = "google-play-id";
43 } 47 }
44 48
45 namespace banners { 49 namespace banners {
46 50
47 AppBannerManager::AppBannerManager(JNIEnv* env, jobject obj) 51 AppBannerManager::AppBannerManager(JNIEnv* env, jobject obj)
48 : weak_java_banner_view_manager_(env, obj) {} 52 : weak_java_banner_view_manager_(env, obj), weak_factory_(this) {
53 }
49 54
50 AppBannerManager::~AppBannerManager() { 55 AppBannerManager::~AppBannerManager() {
51 } 56 }
52 57
53 void AppBannerManager::Destroy(JNIEnv* env, jobject obj) { 58 void AppBannerManager::Destroy(JNIEnv* env, jobject obj) {
54 delete this; 59 delete this;
55 } 60 }
56 61
57 void AppBannerManager::BlockBanner(JNIEnv* env, 62 void AppBannerManager::BlockBanner(JNIEnv* env,
58 jobject obj, 63 jobject obj,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (manifest.IsEmpty() 138 if (manifest.IsEmpty()
134 || !manifest.start_url.is_valid() 139 || !manifest.start_url.is_valid()
135 || (manifest.name.is_null() && manifest.short_name.is_null())) { 140 || (manifest.name.is_null() && manifest.short_name.is_null())) {
136 // No usable manifest, see if there is a play store meta tag. 141 // No usable manifest, see if there is a play store meta tag.
137 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), 142 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(),
138 validated_url_, 143 validated_url_,
139 kBannerTag)); 144 kBannerTag));
140 return; 145 return;
141 } 146 }
142 147
143 // TODO(benwells): Check triggering parameters here and if there is a meta
144 // tag.
145
146 // Create an infobar to promote the manifest's app.
147 manifest_ = manifest; 148 manifest_ = manifest;
148 149
149 GURL icon_url = 150 // Check to see if there is a single service worker controlling this page
150 ManifestIconSelector::FindBestMatchingIcon( 151 // and the manifest's start url.
151 manifest.icons, 152 Profile* profile =
152 GetPreferredIconSize(), 153 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
153 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); 154 content::StoragePartition* storage_partition =
154 if (icon_url.is_empty()) 155 content::BrowserContext::GetStoragePartition(
155 return; 156 profile, web_contents()->GetSiteInstance());
157 DCHECK(storage_partition);
156 158
157 FetchIcon(icon_url); 159 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker(
160 validated_url_, manifest.start_url,
161 base::Bind(&AppBannerManager::OnDidCheckHasServiceWorker,
162 weak_factory_.GetWeakPtr()));
163 }
164
165 void AppBannerManager::OnDidCheckHasServiceWorker(bool has_same) {
nhiroki 2015/02/06 05:36:33 |has_same| -> |has_service_worker|?
benwells 2015/02/06 12:24:59 Done.
166 if (has_same) {
167 // TODO(benwells): Check triggering parameters.
168 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon(
169 manifest_.icons, GetPreferredIconSize(),
170 gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
171 if (icon_url.is_empty())
172 return;
173
174 FetchIcon(icon_url);
175 }
158 } 176 }
159 177
160 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) { 178 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) {
161 bool handled = true; 179 bool handled = true;
162 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message) 180 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message)
163 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, 181 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent,
164 OnDidRetrieveMetaTagContent) 182 OnDidRetrieveMetaTagContent)
165 IPC_MESSAGE_UNHANDLED(handled = false) 183 IPC_MESSAGE_UNHANDLED(handled = false)
166 IPC_END_MESSAGE_MAP() 184 IPC_END_MESSAGE_MAP()
167 return handled; 185 return handled;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return base::CommandLine::ForCurrentProcess()->HasSwitch( 320 return base::CommandLine::ForCurrentProcess()->HasSwitch(
303 switches::kEnableAppInstallAlerts); 321 switches::kEnableAppInstallAlerts);
304 } 322 }
305 323
306 // Register native methods 324 // Register native methods
307 bool RegisterAppBannerManager(JNIEnv* env) { 325 bool RegisterAppBannerManager(JNIEnv* env) {
308 return RegisterNativesImpl(env); 326 return RegisterNativesImpl(env);
309 } 327 }
310 328
311 } // namespace banners 329 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698