| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/extensions/echo_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/echo_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 21 #include "chrome/browser/chromeos/ui/echo_dialog_view.h" | 21 #include "chrome/browser/chromeos/ui/echo_dialog_view.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | |
| 24 #include "chrome/common/extensions/api/echo_private.h" | 23 #include "chrome/common/extensions/api/echo_private.h" |
| 25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 26 #include "chromeos/system/statistics_provider.h" | 25 #include "chromeos/system/statistics_provider.h" |
| 27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/web_contents.h" |
| 28 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 29 | 29 |
| 30 namespace echo_api = extensions::api::echo_private; | 30 namespace echo_api = extensions::api::echo_private; |
| 31 | 31 |
| 32 using content::BrowserThread; | 32 using content::BrowserThread; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // URL of "More info" link shown in echo dialog in GetUserConsent function. | 36 // URL of "More info" link shown in echo dialog in GetUserConsent function. |
| 37 const char kMoreInfoLink[] = | 37 const char kMoreInfoLink[] = |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 echo_api::GetUserConsent::Params::Create(*args_); | 233 echo_api::GetUserConsent::Params::Create(*args_); |
| 234 | 234 |
| 235 // Verify that the passed origin URL is valid. | 235 // Verify that the passed origin URL is valid. |
| 236 GURL service_origin = GURL(params->consent_requester.origin); | 236 GURL service_origin = GURL(params->consent_requester.origin); |
| 237 if (!service_origin.is_valid()) { | 237 if (!service_origin.is_valid()) { |
| 238 error_ = "Invalid origin."; | 238 error_ = "Invalid origin."; |
| 239 SendResponse(false); | 239 SendResponse(false); |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 | 242 |
| 243 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 244 if (!web_contents) { |
| 245 error_ = "No web contents."; |
| 246 SendResponse(false); |
| 247 return; |
| 248 } |
| 249 |
| 243 // Add ref to ensure the function stays around until the dialog listener is | 250 // Add ref to ensure the function stays around until the dialog listener is |
| 244 // called. The reference is release in |Finalize|. | 251 // called. The reference is release in |Finalize|. |
| 245 AddRef(); | 252 AddRef(); |
| 246 | 253 |
| 247 // Create and show the dialog. | 254 // Create and show the dialog. |
| 248 chromeos::EchoDialogView* dialog = new chromeos::EchoDialogView(this); | 255 chromeos::EchoDialogView* dialog = new chromeos::EchoDialogView(this); |
| 249 if (redeem_offers_allowed_) { | 256 if (redeem_offers_allowed_) { |
| 250 dialog->InitForEnabledEcho( | 257 dialog->InitForEnabledEcho( |
| 251 base::UTF8ToUTF16(params->consent_requester.service_name), | 258 base::UTF8ToUTF16(params->consent_requester.service_name), |
| 252 base::UTF8ToUTF16(params->consent_requester.origin)); | 259 base::UTF8ToUTF16(params->consent_requester.origin)); |
| 253 } else { | 260 } else { |
| 254 dialog->InitForDisabledEcho(); | 261 dialog->InitForDisabledEcho(); |
| 255 } | 262 } |
| 256 dialog->Show(GetCurrentBrowser()->window()->GetNativeWindow()); | 263 dialog->Show(web_contents->GetTopLevelNativeWindow()); |
| 257 | 264 |
| 258 // If there is a dialog_shown_callback_, invoke it with the created dialog. | 265 // If there is a dialog_shown_callback_, invoke it with the created dialog. |
| 259 if (!dialog_shown_callback_.is_null()) | 266 if (!dialog_shown_callback_.is_null()) |
| 260 dialog_shown_callback_.Run(dialog); | 267 dialog_shown_callback_.Run(dialog); |
| 261 } | 268 } |
| 262 | 269 |
| 263 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { | 270 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { |
| 264 // Consent should not be true if offers redeeming is disabled. | 271 // Consent should not be true if offers redeeming is disabled. |
| 265 CHECK(redeem_offers_allowed_ || !consent); | 272 CHECK(redeem_offers_allowed_ || !consent); |
| 266 results_ = echo_api::GetUserConsent::Results::Create(consent); | 273 results_ = echo_api::GetUserConsent::Results::Create(consent); |
| 267 SendResponse(true); | 274 SendResponse(true); |
| 268 | 275 |
| 269 // Release the reference added in |OnRedeemOffersAllowedChecked|, before | 276 // Release the reference added in |OnRedeemOffersAllowedChecked|, before |
| 270 // showing the dialog. | 277 // showing the dialog. |
| 271 Release(); | 278 Release(); |
| 272 } | 279 } |
| OLD | NEW |