Home | History | Annotate | Download | only in extensions
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/files/file_path.h"
     12 #include "base/macros.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/memory/weak_ptr.h"
     15 #include "content/public/browser/web_ui_message_handler.h"
     16 
     17 namespace base {
     18 class ListValue;
     19 }
     20 
     21 namespace content {
     22 class WebUIDataSource;
     23 }
     24 
     25 class Profile;
     26 
     27 namespace extensions {
     28 
     29 class Extension;
     30 
     31 // The handler page for the Extension Commands UI overlay.
     32 class ExtensionLoaderHandler : public content::WebUIMessageHandler {
     33  public:
     34   explicit ExtensionLoaderHandler(Profile* profile);
     35   virtual ~ExtensionLoaderHandler();
     36 
     37   // Fetches the localized values for the page and deposits them into |source|.
     38   void GetLocalizedValues(content::WebUIDataSource* source);
     39 
     40   // WebUIMessageHandler implementation.
     41   virtual void RegisterMessages() OVERRIDE;
     42 
     43  private:
     44   class FileHelper;
     45 
     46   // Handle the 'extensionLoaderLoadUnpacked' message.
     47   void HandleLoadUnpacked(const base::ListValue* args);
     48 
     49   // Handle the 'extensionLoaderRetry' message.
     50   void HandleRetry(const base::ListValue* args);
     51 
     52   // Try to load an unpacked extension from the given |file_path|.
     53   void LoadUnpackedExtensionImpl(const base::FilePath& file_path);
     54 
     55   // Called when an unpacked extension fails to load.
     56   void OnLoadFailure(const base::FilePath& file_path, const std::string& error);
     57 
     58   // Notify the frontend of the failure. If it was a manifest error, |manifest|
     59   // will hold the manifest contents, and |line_number| will point to the line
     60   // at which the error was found.
     61   void NotifyFrontendOfFailure(const base::FilePath& file_path,
     62                                const std::string& error,
     63                                size_t line_number,
     64                                const std::string& manifest);
     65 
     66   // The profile with which this Handler is associated.
     67   Profile* profile_;
     68 
     69   // A helper to manage file picking.
     70   scoped_ptr<FileHelper> file_helper_;
     71 
     72   // The file path to the extension that failed to load, or empty. This is
     73   // loaded when the user selects "retry".
     74   base::FilePath failed_path_;
     75 
     76   // Weak pointer factory for posting background tasks.
     77   base::WeakPtrFactory<ExtensionLoaderHandler> weak_ptr_factory_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(ExtensionLoaderHandler);
     80 };
     81 
     82 }  // namespace extensions
     83 
     84 #endif  // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_LOADER_HANDLER_H_
     85