1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (c) 2011 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_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
#pragma once
#include <string>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/browser/extensions/webstore_install_helper.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
class SafeWebstoreResponseParser;
// Manages inline installs requested by a page (downloads and parses metadata
// from the webstore, shows the install UI, starts the download once the user
// confirms). Clients must implement the WebstoreInlineInstaller::Delegate
// interface to be notified when the inline install completes (successfully or
// not). The client will not be notified if the WebContents that this install
// request is attached to goes away.
class WebstoreInlineInstaller
: public base::RefCountedThreadSafe<WebstoreInlineInstaller>,
public ExtensionInstallUI::Delegate,
public content::WebContentsObserver,
public content::URLFetcherDelegate,
public WebstoreInstaller::Delegate,
public WebstoreInstallHelper::Delegate {
public:
class Delegate {
public:
virtual void OnInlineInstallSuccess(int install_id) = 0;
virtual void OnInlineInstallFailure(int install_id,
const std::string& error) = 0;
};
WebstoreInlineInstaller(content::WebContents* web_contents,
int install_id,
std::string webstore_item_id,
GURL requestor_url,
Delegate* d);
void BeginInstall();
private:
friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>;
friend class SafeWebstoreResponseParser;
virtual ~WebstoreInlineInstaller();
// Several delegate/client inteface implementations follow. The normal flow
// (for successful installs) is:
//
// 1. BeginInstall: starts the fetch of data from the webstore
// 2. OnURLFetchComplete: starts the parsing of data from the webstore
// 3. OnWebstoreResponseParseSuccess: starts the parsing of the manifest and
// fetching of icon data.
// 4. OnWebstoreParseSuccess: shows the install UI
// 5. InstallUIProceed: initiates the .crx download/install
//
// All flows (whether successful or not) end up in CompleteInstall, which
// informs our delegate of success/failure.
// content::URLFetcherDelegate interface implementation.
virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
// Client callbacks for SafeWebstoreResponseParser when parsing is complete.
void OnWebstoreResponseParseSuccess(DictionaryValue* webstore_data);
void OnWebstoreResponseParseFailure(const std::string& error);
// WebstoreInstallHelper::Delegate interface implementation.
virtual void OnWebstoreParseSuccess(
const std::string& id,
const SkBitmap& icon,
base::DictionaryValue* parsed_manifest) OVERRIDE;
virtual void OnWebstoreParseFailure(
const std::string& id,
InstallHelperResultCode result_code,
const std::string& error_message) OVERRIDE;
// ExtensionInstallUI::Delegate interface implementation.
virtual void InstallUIProceed() OVERRIDE;
virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
// content::WebContentsObserver interface implementation.
virtual void WebContentsDestroyed(
content::WebContents* web_contents) OVERRIDE;
// WebstoreInstaller::Delegate interface implementation.
virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
virtual void OnExtensionInstallFailure(const std::string& id,
const std::string& error) OVERRIDE;
void CompleteInstall(const std::string& error);
int install_id_;
std::string id_;
GURL requestor_url_;
Delegate* delegate_;
// For fetching webstore JSON data.
scoped_ptr<content::URLFetcher> webstore_data_url_fetcher_;
// Extracted from the webstore JSON data response.
std::string localized_name_;
std::string localized_description_;
std::string localized_user_count_;
double average_rating_;
int rating_count_;
scoped_ptr<DictionaryValue> webstore_data_;
scoped_ptr<DictionaryValue> manifest_;
scoped_refptr<Extension> dummy_extension_;
SkBitmap icon_;
DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
};
#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
|