Commit cc7c70c1 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Add a private API method to install a webstore app from Files.app

This patch is a part of the Webstore-Files.app integration (crbug.com/240152).

BUG=272245
TEST=manually tested

Review URL: https://chromiumcodereview.appspot.com/23332012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220581 0039d316-1c4b-4281-b951-d872f2087c98
parent f8a3912b
...@@ -96,9 +96,12 @@ FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile) ...@@ -96,9 +96,12 @@ FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile)
extensions::FileBrowserPrivateGetPreferencesFunction>(); extensions::FileBrowserPrivateGetPreferencesFunction>();
registry->RegisterFunction< registry->RegisterFunction<
extensions::FileBrowserPrivateSetPreferencesFunction>(); extensions::FileBrowserPrivateSetPreferencesFunction>();
registry->RegisterFunction<
extensions::FileBrowserPrivateInstallWebstoreItemFunction>();
registry->RegisterFunction< registry->RegisterFunction<
extensions::FileBrowserPrivateZipSelectionFunction>(); extensions::FileBrowserPrivateZipSelectionFunction>();
registry->RegisterFunction<extensions::FileBrowserPrivateZoomFunction>(); registry->RegisterFunction<extensions::FileBrowserPrivateZoomFunction>();
event_router_->ObserveFileSystemEvents(); event_router_->ObserveFileSystemEvents();
} }
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_installer.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
namespace file_manager {
namespace {
const char kWebContentsDestroyedError[] = "WebContents is destroyed.";
} // namespace
class FileManagerInstaller::WebContentsObserver
: public content::WebContentsObserver {
public:
explicit WebContentsObserver(
content::WebContents* web_contents,
FileManagerInstaller* parent)
: content::WebContentsObserver(web_contents),
parent_(parent) {
}
protected:
// content::WebContentsObserver implementation.
virtual void WebContentsDestroyed(
content::WebContents* web_contents) OVERRIDE {
parent_->OnWebContentsDestroyed(web_contents);
}
private:
FileManagerInstaller* parent_;
DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsObserver);
};
FileManagerInstaller::FileManagerInstaller(
content::WebContents* web_contents,
const std::string& webstore_item_id,
Profile* profile,
const Callback& callback)
: extensions::WebstoreStandaloneInstaller(
webstore_item_id,
profile,
callback),
callback_(callback),
web_contents_(web_contents),
web_contents_observer_(new WebContentsObserver(web_contents, this)) {
}
FileManagerInstaller::~FileManagerInstaller() {}
bool FileManagerInstaller::CheckRequestorAlive() const {
// The tab may have gone away - cancel installation in that case.
return web_contents_ != NULL;
}
const GURL& FileManagerInstaller::GetRequestorURL() const {
return GURL::EmptyGURL();
}
scoped_ptr<ExtensionInstallPrompt::Prompt>
FileManagerInstaller::CreateInstallPrompt() const {
scoped_ptr<ExtensionInstallPrompt::Prompt> prompt(
new ExtensionInstallPrompt::Prompt(
ExtensionInstallPrompt::INLINE_INSTALL_PROMPT));
prompt->SetInlineInstallWebstoreData(localized_user_count(),
show_user_count(),
average_rating(),
rating_count());
return prompt.Pass();
}
bool FileManagerInstaller::ShouldShowPostInstallUI() const {
return false;
}
bool FileManagerInstaller::ShouldShowAppInstalledBubble() const {
return false;
}
content::WebContents* FileManagerInstaller::GetWebContents() const {
return web_contents_;
}
bool FileManagerInstaller::CheckInlineInstallPermitted(
const base::DictionaryValue& webstore_data,
std::string* error) const {
DCHECK(error != NULL);
DCHECK(error->empty());
return true;
}
bool FileManagerInstaller::CheckRequestorPermitted(
const base::DictionaryValue& webstore_data,
std::string* error) const {
DCHECK(error != NULL);
DCHECK(error->empty());
return true;
}
void FileManagerInstaller::OnWebContentsDestroyed(
content::WebContents* web_contents) {
callback_.Run(false, kWebContentsDestroyedError);
AbortInstall();
}
} // namespace file_manager
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_INSTALLER_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_INSTALLER_H_
#include <string>
#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/webstore_standalone_installer.h"
#include "content/public/browser/web_contents_observer.h"
namespace content {
class WebContents;
}
namespace file_manager {
// Installer for Files.app.
class FileManagerInstaller
: public extensions::WebstoreStandaloneInstaller {
public:
typedef extensions::WebstoreStandaloneInstaller::Callback Callback;
FileManagerInstaller(content::WebContents* web_contents,
const std::string& webstore_item_id,
Profile* profile,
const Callback& callback);
protected:
friend class base::RefCountedThreadSafe<FileManagerInstaller>;
virtual ~FileManagerInstaller();
void OnWebContentsDestroyed(content::WebContents* web_contents);
// WebstoreStandaloneInstaller implementation.
virtual bool CheckRequestorAlive() const OVERRIDE;
virtual const GURL& GetRequestorURL() const OVERRIDE;
virtual bool ShouldShowPostInstallUI() const OVERRIDE;
virtual bool ShouldShowAppInstalledBubble() const OVERRIDE;
virtual content::WebContents* GetWebContents() const OVERRIDE;
virtual scoped_ptr<ExtensionInstallPrompt::Prompt>
CreateInstallPrompt() const OVERRIDE;
virtual bool CheckInlineInstallPermitted(
const base::DictionaryValue& webstore_data,
std::string* error) const OVERRIDE;
virtual bool CheckRequestorPermitted(
const base::DictionaryValue& webstore_data,
std::string* error) const OVERRIDE;
private:
class WebContentsObserver;
Callback callback_;
content::WebContents* web_contents_;
scoped_ptr<WebContentsObserver> web_contents_observer_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FileManagerInstaller);
};
} // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_INSTALLER_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h" #include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/logging.h" #include "chrome/browser/chromeos/drive/logging.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_installer.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
...@@ -204,4 +205,53 @@ bool FileBrowserPrivateZoomFunction::RunImpl() { ...@@ -204,4 +205,53 @@ bool FileBrowserPrivateZoomFunction::RunImpl() {
return true; return true;
} }
FileBrowserPrivateInstallWebstoreItemFunction::
FileBrowserPrivateInstallWebstoreItemFunction() {
}
FileBrowserPrivateInstallWebstoreItemFunction::
~FileBrowserPrivateInstallWebstoreItemFunction() {
}
bool FileBrowserPrivateInstallWebstoreItemFunction::RunImpl() {
if (args_->GetSize() < 1)
return false;
if (!args_->GetString(0, &webstore_item_id_) || webstore_item_id_.empty())
return false;
extensions::WebstoreStandaloneInstaller::Callback callback =
base::Bind(
&FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete,
this);
scoped_refptr<file_manager::FileManagerInstaller> installer(
new file_manager::FileManagerInstaller(
GetAssociatedWebContents(), // web_contents(),
webstore_item_id_,
profile(),
callback));
// installer will be AddRef()'d in BeginInstall().
installer->BeginInstall();
return true;
}
void FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete(
bool success,
const std::string& error) {
if (success) {
drive::util::Log(logging::LOG_INFO,
"App install succeeded. (item id: %s)",
webstore_item_id_.c_str());
} else {
drive::util::Log(logging::LOG_ERROR,
"App install failed. (item id: %s, reason: %s)",
webstore_item_id_.c_str(),
error.c_str());
error_ = error;
}
SendResponse(success);
}
} // namespace extensions } // namespace extensions
...@@ -98,6 +98,24 @@ class FileBrowserPrivateZoomFunction : public SyncExtensionFunction { ...@@ -98,6 +98,24 @@ class FileBrowserPrivateZoomFunction : public SyncExtensionFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
}; };
// Implements the chrome.fileBrowserPrivate.installWebstoreItem method.
class FileBrowserPrivateInstallWebstoreItemFunction
: public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.installWebstoreItem",
FILEBROWSERPRIVATE_INSTALLWEBSTOREITEM);
FileBrowserPrivateInstallWebstoreItemFunction();
protected:
virtual ~FileBrowserPrivateInstallWebstoreItemFunction();
virtual bool RunImpl() OVERRIDE;
void OnInstallComplete(bool success, const std::string& error);
private:
std::string webstore_item_id_;
};
} // namespace extensions } // namespace extensions
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_MISC_H_ #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_MISC_H_
...@@ -618,6 +618,7 @@ enum HistogramValue { ...@@ -618,6 +618,7 @@ enum HistogramValue {
ECHOPRIVATE_SETOFFERINFO, ECHOPRIVATE_SETOFFERINFO,
ECHOPRIVATE_GETOFFERINFO, ECHOPRIVATE_GETOFFERINFO,
DEVELOPERPRIVATE_ISPROFILEMANAGED, DEVELOPERPRIVATE_ISPROFILEMANAGED,
FILEBROWSERPRIVATE_INSTALLWEBSTOREITEM,
ENUM_BOUNDARY // Last entry: Add new entries above. ENUM_BOUNDARY // Last entry: Add new entries above.
}; };
......
...@@ -350,6 +350,8 @@ ...@@ -350,6 +350,8 @@
'browser/chromeos/extensions/file_manager/select_file_dialog_util.h', 'browser/chromeos/extensions/file_manager/select_file_dialog_util.h',
'browser/chromeos/extensions/file_manager/url_util.cc', 'browser/chromeos/extensions/file_manager/url_util.cc',
'browser/chromeos/extensions/file_manager/url_util.h', 'browser/chromeos/extensions/file_manager/url_util.h',
'browser/chromeos/extensions/file_manager/file_manager_installer.cc',
'browser/chromeos/extensions/file_manager/file_manager_installer.h',
'browser/chromeos/extensions/file_manager/zip_file_creator.cc', 'browser/chromeos/extensions/file_manager/zip_file_creator.cc',
'browser/chromeos/extensions/file_manager/zip_file_creator.h', 'browser/chromeos/extensions/file_manager/zip_file_creator.h',
'browser/chromeos/extensions/info_private_api.cc', 'browser/chromeos/extensions/info_private_api.cc',
......
...@@ -1132,6 +1132,23 @@ ...@@ -1132,6 +1132,23 @@
] ]
} }
] ]
},
{
"name": "installWebstoreItem",
"type": "function",
"description": "Requests to install a webstore item.",
"parameters": [
{
"name": "item_id",
"type": "string",
"description": "The id of the item to install."
},
{
"name": "callback",
"type": "function",
"parameters": []
}
]
} }
], ],
"events": [ "events": [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment