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/webapps/add_to_homescreen_dialog_helper.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, | 113 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, |
114 const SkBitmap& icon) { | 114 const SkBitmap& icon) { |
115 DCHECK(add_shortcut_pending_); | 115 DCHECK(add_shortcut_pending_); |
116 if (!add_shortcut_pending_) | 116 if (!add_shortcut_pending_) |
117 return; | 117 return; |
118 add_shortcut_pending_ = false; | 118 add_shortcut_pending_ = false; |
119 | 119 |
| 120 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 121 if (!web_contents) |
| 122 return; |
| 123 |
120 RecordAddToHomescreen(); | 124 RecordAddToHomescreen(); |
121 | 125 |
122 const std::string& uid = base::GenerateGUID(); | 126 const std::string& uid = base::GenerateGUID(); |
123 content::BrowserThread::PostTask( | 127 content::BrowserThread::PostTask( |
124 content::BrowserThread::IO, FROM_HERE, | 128 content::BrowserThread::IO, FROM_HERE, |
125 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, info, | 129 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, |
126 uid, icon, | 130 web_contents->GetBrowserContext(), info, uid, icon, |
127 data_fetcher_->FetchSplashScreenImageCallback(uid))); | 131 data_fetcher_->FetchSplashScreenImageCallback(uid))); |
128 } | 132 } |
129 | 133 |
130 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( | 134 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( |
131 JNIEnv* env) { | 135 JNIEnv* env) { |
132 return RegisterNativesImpl(env); | 136 return RegisterNativesImpl(env); |
133 } | 137 } |
134 | 138 |
135 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { | 139 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { |
136 // Record that the shortcut has been added, so no banners will be shown | 140 // Record that the shortcut has been added, so no banners will be shown |
137 // for this app. | 141 // for this app. |
138 content::WebContents* web_contents = data_fetcher_->web_contents(); | 142 content::WebContents* web_contents = data_fetcher_->web_contents(); |
139 if (!web_contents) | 143 if (!web_contents) |
140 return; | 144 return; |
141 | 145 |
142 AppBannerSettingsHelper::RecordBannerEvent( | 146 AppBannerSettingsHelper::RecordBannerEvent( |
143 web_contents, web_contents->GetURL(), | 147 web_contents, web_contents->GetURL(), |
144 data_fetcher_->shortcut_info().url.spec(), | 148 data_fetcher_->shortcut_info().url.spec(), |
145 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 149 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
146 base::Time::Now()); | 150 base::Time::Now()); |
147 } | 151 } |
OLD | NEW |