File: extension_reenabler.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (130 lines) | stat: -rw-r--r-- 4,671 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
// Copyright 2014 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_EXTENSION_REENABLER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_

#include <memory>

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
#include "extensions/browser/extension_registry_observer.h"

namespace content {
class BrowserContext;
}

namespace extensions {

class Extension;
class ExtensionRegistry;
class WebstoreDataFetcher;

// A class to handle reenabling an extension disabled due to a permissions
// increase.
// TODO(devlin): Once we get the UI figured out, we should also have this handle
// other disable reasons.
class ExtensionReenabler : public ExtensionRegistryObserver,
                           public WebstoreDataFetcherDelegate {
 public:
  enum ReenableResult {
    REENABLE_SUCCESS,  // The extension has been successfully re-enabled.
    USER_CANCELED,     // The user chose to not re-enable the extension.
    NOT_ALLOWED,       // The re-enable is not allowed.
    ABORTED,           // The re-enable process was aborted due to, e.g.,
                       // shutdown or a bad webstore response.
  };

  using Callback = base::Callback<void(ReenableResult)>;

  ~ExtensionReenabler() override;

  // Prompts the user to reenable the given |extension|, and calls |callback|
  // upon completion.
  // If |referrer_url| is non-empty, then this will also check to make sure
  // that the referrer_url is listed as a trusted url by the extension.
  static std::unique_ptr<ExtensionReenabler> PromptForReenable(
      const scoped_refptr<const Extension>& extension,
      content::BrowserContext* browser_context,
      content::WebContents* web_contents,
      const GURL& referrer_url,
      const Callback& callback);

  // Like PromptForReenable, but allows tests to inject the
  // ExtensionInstallPrompt.
  static std::unique_ptr<ExtensionReenabler>
  PromptForReenableWithCallbackForTest(
      const scoped_refptr<const Extension>& extension,
      content::BrowserContext* browser_context,
      const Callback& callback,
      const ExtensionInstallPrompt::ShowDialogCallback& show_callback);

 private:
  ExtensionReenabler(
      const scoped_refptr<const Extension>& extension,
      content::BrowserContext* browser_context,
      const GURL& referrer_url,
      const Callback& callback,
      content::WebContents* web_contents,
      const ExtensionInstallPrompt::ShowDialogCallback& show_callback);

  void OnInstallPromptDone(ExtensionInstallPrompt::Result result);

  // ExtensionRegistryObserver:
  void OnExtensionLoaded(content::BrowserContext* browser_context,
                         const Extension* extension) override;
  void OnExtensionUninstalled(content::BrowserContext* browser_context,
                              const Extension* extension,
                              UninstallReason reason) override;

  // WebstoreDataFetcherDelegate:
  void OnWebstoreRequestFailure() override;
  void OnWebstoreResponseParseSuccess(
      std::unique_ptr<base::DictionaryValue> webstore_data) override;
  void OnWebstoreResponseParseFailure(const std::string& error) override;

  // Sets the |finished_| bit and runs |callback_| with the given |result|.
  void Finish(ReenableResult result);

  // The extension to be re-enabled.
  scoped_refptr<const Extension> extension_;

  // The associated browser context.
  content::BrowserContext* browser_context_;

  // The url of the referrer, if any. If this is non-empty, it means we have
  // to check that the url is trusted by the extension.
  GURL referrer_url_;

  // The callback to run upon completion.
  Callback callback_;

  // The callback to use to show the dialog.
  ExtensionInstallPrompt::ShowDialogCallback show_dialog_callback_;

  // The re-enable prompt.
  std::unique_ptr<ExtensionInstallPrompt> install_prompt_;

  // Indicates whether the re-enable process finished.
  bool finished_;

  // The data fetcher for retrieving webstore data.
  std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_;

  ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
      registry_observer_;

  base::WeakPtrFactory<ExtensionReenabler> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionReenabler);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_