OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_manager/app_installer.h" | 5 #include "chrome/browser/chromeos/file_manager/app_installer.h" |
6 | 6 |
7 #include "chrome/common/extensions/webstore_install_result.h" | 7 #include "chrome/common/extensions/webstore_install_result.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
10 | 10 |
11 namespace file_manager { | 11 namespace file_manager { |
12 | 12 |
13 namespace { | 13 namespace { |
14 const char kWebContentsDestroyedError[] = "WebContents is destroyed."; | 14 const char kWebContentsDestroyedError[] = "WebContents is destroyed."; |
15 | |
16 const char kGoogleCastApiExtensionId[] = "mafeflapfdfljijmlienjedomfjfmhpd"; | |
15 } // namespace | 17 } // namespace |
16 | 18 |
17 class AppInstaller::WebContentsObserver : public content::WebContentsObserver { | 19 class AppInstaller::WebContentsObserver : public content::WebContentsObserver { |
18 public: | 20 public: |
19 WebContentsObserver(content::WebContents* web_contents, AppInstaller* parent) | 21 WebContentsObserver(content::WebContents* web_contents, AppInstaller* parent) |
20 : content::WebContentsObserver(web_contents), | 22 : content::WebContentsObserver(web_contents), |
21 parent_(parent) { | 23 parent_(parent) { |
22 } | 24 } |
23 | 25 |
24 protected: | 26 protected: |
25 // content::WebContentsObserver implementation. | 27 // content::WebContentsObserver implementation. |
26 virtual void WebContentsDestroyed() OVERRIDE { | 28 virtual void WebContentsDestroyed() OVERRIDE { |
27 parent_->OnWebContentsDestroyed(web_contents()); | 29 parent_->OnWebContentsDestroyed(web_contents()); |
28 } | 30 } |
29 | 31 |
30 private: | 32 private: |
31 AppInstaller* parent_; | 33 AppInstaller* parent_; |
32 | 34 |
33 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver); | 35 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver); |
34 }; | 36 }; |
35 | 37 |
36 AppInstaller::AppInstaller(content::WebContents* web_contents, | 38 AppInstaller::AppInstaller(content::WebContents* web_contents, |
37 const std::string& item_id, | 39 const std::string& item_id, |
38 Profile* profile, | 40 Profile* profile, |
41 bool silent_installation, | |
39 const Callback& callback) | 42 const Callback& callback) |
40 : extensions::WebstoreStandaloneInstaller(item_id, profile, callback), | 43 : extensions::WebstoreStandaloneInstaller(item_id, profile, callback), |
44 silent_installation_(silent_installation), | |
41 callback_(callback), | 45 callback_(callback), |
42 web_contents_(web_contents), | 46 web_contents_(web_contents), |
43 web_contents_observer_(new WebContentsObserver(web_contents, this)) { | 47 web_contents_observer_(new WebContentsObserver(web_contents, this)) { |
48 // Only GoogleCastAPI extension can use silent installation. | |
49 if (silent_installation_ && item_id != kGoogleCastApiExtensionId) | |
50 silent_installation_ = false; | |
hashimoto
2014/08/01 10:40:31
Can't we raise an error in this case?
yoshiki
2014/08/01 11:46:41
Done. This handles in the caller.
| |
44 } | 51 } |
45 | 52 |
46 AppInstaller::~AppInstaller() {} | 53 AppInstaller::~AppInstaller() {} |
47 | 54 |
48 bool AppInstaller::CheckRequestorAlive() const { | 55 bool AppInstaller::CheckRequestorAlive() const { |
49 // The tab may have gone away - cancel installation in that case. | 56 // The tab may have gone away - cancel installation in that case. |
50 return web_contents_ != NULL; | 57 return web_contents_ != NULL; |
51 } | 58 } |
52 | 59 |
53 const GURL& AppInstaller::GetRequestorURL() const { | 60 const GURL& AppInstaller::GetRequestorURL() const { |
54 return GURL::EmptyGURL(); | 61 return GURL::EmptyGURL(); |
55 } | 62 } |
56 | 63 |
57 scoped_refptr<ExtensionInstallPrompt::Prompt> | 64 scoped_refptr<ExtensionInstallPrompt::Prompt> |
58 AppInstaller::CreateInstallPrompt() const { | 65 AppInstaller::CreateInstallPrompt() const { |
66 if (silent_installation_) | |
67 return NULL; | |
68 | |
59 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt( | 69 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt( |
60 new ExtensionInstallPrompt::Prompt( | 70 new ExtensionInstallPrompt::Prompt( |
61 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT)); | 71 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT)); |
62 | 72 |
63 prompt->SetWebstoreData(localized_user_count(), | 73 prompt->SetWebstoreData(localized_user_count(), |
64 show_user_count(), | 74 show_user_count(), |
65 average_rating(), | 75 average_rating(), |
66 rating_count()); | 76 rating_count()); |
67 return prompt; | 77 return prompt; |
68 } | 78 } |
(...skipping 28 matching lines...) Expand all Loading... | |
97 | 107 |
98 void AppInstaller::OnWebContentsDestroyed( | 108 void AppInstaller::OnWebContentsDestroyed( |
99 content::WebContents* web_contents) { | 109 content::WebContents* web_contents) { |
100 callback_.Run(false, | 110 callback_.Run(false, |
101 kWebContentsDestroyedError, | 111 kWebContentsDestroyedError, |
102 extensions::webstore_install::OTHER_ERROR); | 112 extensions::webstore_install::OTHER_ERROR); |
103 AbortInstall(); | 113 AbortInstall(); |
104 } | 114 } |
105 | 115 |
106 } // namespace file_manager | 116 } // namespace file_manager |
OLD | NEW |