Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.h

Issue 150663013: Integrate ErrorConsole with Apps Dev Tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dan's and Finnur's Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_
7 7
8 #include <set>
9
8 #include "base/files/file.h" 10 #include "base/files/file.h"
9 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 11 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 12 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h" 13 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/extensions/error_console/error_console.h"
12 #include "chrome/browser/extensions/extension_install_prompt.h" 15 #include "chrome/browser/extensions/extension_install_prompt.h"
13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 16 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
14 #include "chrome/browser/extensions/pack_extension_job.h" 17 #include "chrome/browser/extensions/pack_extension_job.h"
15 #include "chrome/browser/extensions/requirements_checker.h" 18 #include "chrome/browser/extensions/requirements_checker.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 19 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
17 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
20 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
21 #include "ui/shell_dialogs/select_file_dialog.h" 24 #include "ui/shell_dialogs/select_file_dialog.h"
22 #include "webkit/browser/fileapi/file_system_context.h" 25 #include "webkit/browser/fileapi/file_system_context.h"
23 #include "webkit/browser/fileapi/file_system_operation.h" 26 #include "webkit/browser/fileapi/file_system_operation.h"
24 27
25 class ExtensionService; 28 class ExtensionService;
26 29
27 namespace extensions { 30 namespace extensions {
28 31
32 class ExtensionError;
29 class ExtensionSystem; 33 class ExtensionSystem;
30 class ManagementPolicy; 34 class ManagementPolicy;
31 35
32 namespace api { 36 namespace api {
33 37
34 class EntryPicker; 38 class EntryPicker;
35 class EntryPickerClient; 39 class EntryPickerClient;
36 40
37 namespace developer_private { 41 namespace developer_private {
38 42
39 struct ItemInfo; 43 struct ItemInfo;
40 struct ItemInspectView; 44 struct ItemInspectView;
41 struct ProjectInfo; 45 struct ProjectInfo;
42 46
43 } 47 } // namespace developer_private
44 48
45 } // namespace api 49 } // namespace api
46 50
47 } // namespace extensions 51 namespace developer = api::developer_private;
48
49 namespace developer = extensions::api::developer_private;
50 52
51 typedef std::vector<linked_ptr<developer::ItemInfo> > ItemInfoList; 53 typedef std::vector<linked_ptr<developer::ItemInfo> > ItemInfoList;
52 typedef std::vector<linked_ptr<developer::ProjectInfo> > ProjectInfoList; 54 typedef std::vector<linked_ptr<developer::ProjectInfo> > ProjectInfoList;
53 typedef std::vector<linked_ptr<developer::ItemInspectView> > 55 typedef std::vector<linked_ptr<developer::ItemInspectView> >
54 ItemInspectViewList; 56 ItemInspectViewList;
55 57
56 namespace extensions { 58 class DeveloperPrivateEventRouter : public content::NotificationObserver,
57 59 public ErrorConsole::Observer {
58 class DeveloperPrivateEventRouter : public content::NotificationObserver {
59 public: 60 public:
60 explicit DeveloperPrivateEventRouter(Profile* profile); 61 explicit DeveloperPrivateEventRouter(Profile* profile);
61 virtual ~DeveloperPrivateEventRouter(); 62 virtual ~DeveloperPrivateEventRouter();
62 63
64 // Add or remove an ID to the list of extensions subscribed to events.
65 void AddExtensionId(const std::string& extension_id);
66 void RemoveExtensionId(const std::string& extension_id);
67
63 private: 68 private:
64 // content::NotificationObserver implementation 69 // content::NotificationObserver implementation
65 virtual void Observe(int type, 70 virtual void Observe(int type,
66 const content::NotificationSource& source, 71 const content::NotificationSource& source,
67 const content::NotificationDetails& details) OVERRIDE; 72 const content::NotificationDetails& details) OVERRIDE;
68 73
74 // ErrorConsole::Observer implementation
75 virtual void OnErrorAdded(const ExtensionError* error) OVERRIDE;
76
69 content::NotificationRegistrar registrar_; 77 content::NotificationRegistrar registrar_;
70 78
71 Profile* profile_; 79 Profile* profile_;
72 80
81 // The set of IDs of the Extensions that have subscribed to DeveloperPrivate
82 // events. Since the only consumer of the DeveloperPrivate API is currently
83 // the Apps Developer Tool (which replaces the chrome://extensions page), we
84 // don't want to send information about the subscribing extension in an
85 // update. In particular, we want to avoid entering a loop, which could happen
86 // when, e.g., the Apps Developer Tool throws an error.
87 std::set<std::string> extension_ids_;
88
73 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateEventRouter); 89 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateEventRouter);
74 }; 90 };
75 91
76 // The profile-keyed service that manages the DeveloperPrivate API. 92 // The profile-keyed service that manages the DeveloperPrivate API.
77 class DeveloperPrivateAPI : public BrowserContextKeyedService, 93 class DeveloperPrivateAPI : public BrowserContextKeyedService,
78 public extensions::EventRouter::Observer { 94 public EventRouter::Observer {
79 public: 95 public:
80 // Convenience method to get the DeveloperPrivateAPI for a profile. 96 // Convenience method to get the DeveloperPrivateAPI for a profile.
81 static DeveloperPrivateAPI* Get(Profile* profile); 97 static DeveloperPrivateAPI* Get(Profile* profile);
82 98
83 explicit DeveloperPrivateAPI(Profile* profile); 99 explicit DeveloperPrivateAPI(Profile* profile);
84 virtual ~DeveloperPrivateAPI(); 100 virtual ~DeveloperPrivateAPI();
85 101
86 void SetLastUnpackedDirectory(const base::FilePath& path); 102 void SetLastUnpackedDirectory(const base::FilePath& path);
87 103
88 base::FilePath& GetLastUnpackedDirectory() { 104 base::FilePath& GetLastUnpackedDirectory() {
89 return last_unpacked_directory_; 105 return last_unpacked_directory_;
90 } 106 }
91 107
92 // BrowserContextKeyedService implementation 108 // BrowserContextKeyedService implementation
93 virtual void Shutdown() OVERRIDE; 109 virtual void Shutdown() OVERRIDE;
94 110
95 // EventRouter::Observer implementation. 111 // EventRouter::Observer implementation.
96 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) 112 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
97 OVERRIDE; 113 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
98 virtual void OnListenerRemoved(const extensions::EventListenerInfo& details)
99 OVERRIDE;
100 114
101 private: 115 private:
102 void RegisterNotifications(); 116 void RegisterNotifications();
103 117
104 Profile* profile_; 118 Profile* profile_;
105 119
106 // Used to start the load |load_extension_dialog_| in the last directory that 120 // Used to start the load |load_extension_dialog_| in the last directory that
107 // was loaded. 121 // was loaded.
108 base::FilePath last_unpacked_directory_; 122 base::FilePath last_unpacked_directory_;
109 123
(...skipping 24 matching lines...) Expand all
134 DECLARE_EXTENSION_FUNCTION("developerPrivate.getItemsInfo", 148 DECLARE_EXTENSION_FUNCTION("developerPrivate.getItemsInfo",
135 DEVELOPERPRIVATE_GETITEMSINFO) 149 DEVELOPERPRIVATE_GETITEMSINFO)
136 150
137 protected: 151 protected:
138 virtual ~DeveloperPrivateGetItemsInfoFunction(); 152 virtual ~DeveloperPrivateGetItemsInfoFunction();
139 153
140 // ExtensionFunction: 154 // ExtensionFunction:
141 virtual bool RunImpl() OVERRIDE; 155 virtual bool RunImpl() OVERRIDE;
142 156
143 private: 157 private:
144 158 scoped_ptr<developer::ItemInfo> CreateItemInfo(const Extension& item,
145 scoped_ptr<developer::ItemInfo> CreateItemInfo( 159 bool item_is_enabled);
146 const extensions::Extension& item,
147 bool item_is_enabled);
148 160
149 void GetIconsOnFileThread( 161 void GetIconsOnFileThread(
150 ItemInfoList item_list, 162 ItemInfoList item_list,
151 std::map<std::string, ExtensionResource> itemIdToIconResourceMap); 163 std::map<std::string, ExtensionResource> itemIdToIconResourceMap);
152 164
153 // Helper that lists the current inspectable html pages for the extension. 165 // Helper that lists the current inspectable html pages for the extension.
154 void GetInspectablePagesForExtensionProcess( 166 void GetInspectablePagesForExtensionProcess(
155 const Extension* extension, 167 const Extension* extension,
156 const std::set<content::RenderViewHost*>& views, 168 const std::set<content::RenderViewHost*>& views,
157 ItemInspectViewList* result); 169 ItemInspectViewList* result);
158 170
159 ItemInspectViewList GetInspectablePagesForExtension( 171 ItemInspectViewList GetInspectablePagesForExtension(
160 const extensions::Extension* extension, 172 const Extension* extension,
161 bool extension_is_enabled); 173 bool extension_is_enabled);
162 174
163 void GetShellWindowPagesForExtensionProfile( 175 void GetShellWindowPagesForExtensionProfile(const Extension* extension,
164 const extensions::Extension* extension, 176 ItemInspectViewList* result);
165 ItemInspectViewList* result);
166 177
167 linked_ptr<developer::ItemInspectView> constructInspectView( 178 linked_ptr<developer::ItemInspectView> constructInspectView(
168 const GURL& url, 179 const GURL& url,
169 int render_process_id, 180 int render_process_id,
170 int render_view_id, 181 int render_view_id,
171 bool incognito, 182 bool incognito,
172 bool generated_background_page); 183 bool generated_background_page);
173 }; 184 };
174 185
175 class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction { 186 class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 protected: 268 protected:
258 virtual ~DeveloperPrivateEnableFunction(); 269 virtual ~DeveloperPrivateEnableFunction();
259 270
260 // Callback for requirements checker. 271 // Callback for requirements checker.
261 void OnRequirementsChecked(std::string extension_id, 272 void OnRequirementsChecked(std::string extension_id,
262 std::vector<std::string> requirements_errors); 273 std::vector<std::string> requirements_errors);
263 // ExtensionFunction: 274 // ExtensionFunction:
264 virtual bool RunImpl() OVERRIDE; 275 virtual bool RunImpl() OVERRIDE;
265 276
266 private: 277 private:
267 scoped_ptr<extensions::RequirementsChecker> requirements_checker_; 278 scoped_ptr<RequirementsChecker> requirements_checker_;
268 }; 279 };
269 280
270 class DeveloperPrivateChooseEntryFunction : public ChromeAsyncExtensionFunction, 281 class DeveloperPrivateChooseEntryFunction : public ChromeAsyncExtensionFunction,
271 public EntryPickerClient { 282 public EntryPickerClient {
272 protected: 283 protected:
273 virtual ~DeveloperPrivateChooseEntryFunction(); 284 virtual ~DeveloperPrivateChooseEntryFunction();
274 virtual bool RunImpl() OVERRIDE; 285 virtual bool RunImpl() OVERRIDE;
275 bool ShowPicker(ui::SelectFileDialog::Type picker_type, 286 bool ShowPicker(ui::SelectFileDialog::Type picker_type,
276 const base::FilePath& last_directory, 287 const base::FilePath& last_directory,
277 const base::string16& select_title, 288 const base::string16& select_title,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 virtual ~DeveloperPrivateChoosePathFunction(); 320 virtual ~DeveloperPrivateChoosePathFunction();
310 virtual bool RunImpl() OVERRIDE; 321 virtual bool RunImpl() OVERRIDE;
311 322
312 // EntryPickerClient functions. 323 // EntryPickerClient functions.
313 virtual void FileSelected(const base::FilePath& path) OVERRIDE; 324 virtual void FileSelected(const base::FilePath& path) OVERRIDE;
314 virtual void FileSelectionCanceled() OVERRIDE; 325 virtual void FileSelectionCanceled() OVERRIDE;
315 }; 326 };
316 327
317 class DeveloperPrivatePackDirectoryFunction 328 class DeveloperPrivatePackDirectoryFunction
318 : public ChromeAsyncExtensionFunction, 329 : public ChromeAsyncExtensionFunction,
319 public extensions::PackExtensionJob::Client { 330 public PackExtensionJob::Client {
320 331
321 public: 332 public:
322 DECLARE_EXTENSION_FUNCTION("developerPrivate.packDirectory", 333 DECLARE_EXTENSION_FUNCTION("developerPrivate.packDirectory",
323 DEVELOPERPRIVATE_PACKDIRECTORY); 334 DEVELOPERPRIVATE_PACKDIRECTORY);
324 335
325 DeveloperPrivatePackDirectoryFunction(); 336 DeveloperPrivatePackDirectoryFunction();
326 337
327 // ExtensionPackJob::Client implementation. 338 // ExtensionPackJob::Client implementation.
328 virtual void OnPackSuccess(const base::FilePath& crx_file, 339 virtual void OnPackSuccess(const base::FilePath& crx_file,
329 const base::FilePath& key_file) OVERRIDE; 340 const base::FilePath& key_file) OVERRIDE;
330 virtual void OnPackFailure( 341 virtual void OnPackFailure(const std::string& error,
331 const std::string& error, 342 ExtensionCreator::ErrorType error_type) OVERRIDE;
332 extensions::ExtensionCreator::ErrorType error_type) OVERRIDE;
333 343
334 protected: 344 protected:
335 virtual ~DeveloperPrivatePackDirectoryFunction(); 345 virtual ~DeveloperPrivatePackDirectoryFunction();
336 virtual bool RunImpl() OVERRIDE; 346 virtual bool RunImpl() OVERRIDE;
337 347
338 private: 348 private:
339 scoped_refptr<extensions::PackExtensionJob> pack_job_; 349 scoped_refptr<PackExtensionJob> pack_job_;
340 std::string item_path_str_; 350 std::string item_path_str_;
341 std::string key_path_str_; 351 std::string key_path_str_;
342 }; 352 };
343 353
344 class DeveloperPrivateGetStringsFunction : public ChromeSyncExtensionFunction {
345 public:
346 DECLARE_EXTENSION_FUNCTION("developerPrivate.getStrings",
347 DEVELOPERPRIVATE_GETSTRINGS);
348
349 protected:
350 virtual ~DeveloperPrivateGetStringsFunction();
351
352 // ExtensionFunction
353 virtual bool RunImpl() OVERRIDE;
354 };
355
356 class DeveloperPrivateIsProfileManagedFunction 354 class DeveloperPrivateIsProfileManagedFunction
357 : public ChromeSyncExtensionFunction { 355 : public ChromeSyncExtensionFunction {
358 public: 356 public:
359 DECLARE_EXTENSION_FUNCTION("developerPrivate.isProfileManaged", 357 DECLARE_EXTENSION_FUNCTION("developerPrivate.isProfileManaged",
360 DEVELOPERPRIVATE_ISPROFILEMANAGED); 358 DEVELOPERPRIVATE_ISPROFILEMANAGED);
361 359
362 protected: 360 protected:
363 virtual ~DeveloperPrivateIsProfileManagedFunction(); 361 virtual ~DeveloperPrivateIsProfileManagedFunction();
364 362
365 // ExtensionFunction 363 // ExtensionFunction
366 virtual bool RunImpl() OVERRIDE; 364 virtual bool RunImpl() OVERRIDE;
367 }; 365 };
368 366
369 class DeveloperPrivateLoadDirectoryFunction 367 class DeveloperPrivateLoadDirectoryFunction
370 : public ChromeAsyncExtensionFunction { 368 : public ChromeAsyncExtensionFunction {
371 public: 369 public:
372 DECLARE_EXTENSION_FUNCTION("developerPrivate.loadDirectory", 370 DECLARE_EXTENSION_FUNCTION("developerPrivate.loadDirectory",
373 DEVELOPERPRIVATE_LOADUNPACKEDCROS); 371 DEVELOPERPRIVATE_LOADUNPACKEDCROS);
374 372
375 DeveloperPrivateLoadDirectoryFunction(); 373 DeveloperPrivateLoadDirectoryFunction();
376 374
377 protected: 375 protected:
378 virtual ~DeveloperPrivateLoadDirectoryFunction(); 376 virtual ~DeveloperPrivateLoadDirectoryFunction();
379 377
380 // ExtensionFunction 378 // ExtensionFunction
381 virtual bool RunImpl() OVERRIDE; 379 virtual bool RunImpl() OVERRIDE;
382 380
383 void ClearExistingDirectoryContent(const base::FilePath& project_path); 381 void ClearExistingDirectoryContent(const base::FilePath& project_path);
384 382
385 void ReadSyncFileSystemDirectory(const base::FilePath& project_path, 383 void ReadSyncFileSystemDirectory(const base::FilePath& project_path,
386 const base::FilePath& destination_path); 384 const base::FilePath& destination_path);
387 385
388 void ReadSyncFileSystemDirectoryCb( 386 void ReadSyncFileSystemDirectoryCb(
389 const base::FilePath& project_path, 387 const base::FilePath& project_path,
390 const base::FilePath& destination_path, 388 const base::FilePath& destination_path,
391 base::File::Error result, 389 base::File::Error result,
392 const fileapi::FileSystemOperation::FileEntryList& file_list, 390 const fileapi::FileSystemOperation::FileEntryList& file_list,
393 bool has_more); 391 bool has_more);
394 392
395 void SnapshotFileCallback( 393 void SnapshotFileCallback(
396 const base::FilePath& target_path, 394 const base::FilePath& target_path,
397 base::File::Error result, 395 base::File::Error result,
398 const base::File::Info& file_info, 396 const base::File::Info& file_info,
399 const base::FilePath& platform_path, 397 const base::FilePath& platform_path,
400 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); 398 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
401 399
402 void CopyFile(const base::FilePath& src_path, 400 void CopyFile(const base::FilePath& src_path,
403 const base::FilePath& dest_path); 401 const base::FilePath& dest_path);
404 402
405 void Load(); 403 void Load();
406 404
407 scoped_refptr<fileapi::FileSystemContext> context_; 405 scoped_refptr<fileapi::FileSystemContext> context_;
408 406
409 // syncfs url representing the root of the folder to be copied. 407 // syncfs url representing the root of the folder to be copied.
410 std::string project_base_url_; 408 std::string project_base_url_;
411 409
412 // physical path on disc of the folder to be copied. 410 // physical path on disc of the folder to be copied.
413 base::FilePath project_base_path_; 411 base::FilePath project_base_path_;
414 412
415 // Path of the current folder to be copied. 413 // Path of the current folder to be copied.
416 base::FilePath current_path_; 414 base::FilePath current_path_;
417 415
418 private: 416 private:
419 int pending_copy_operations_count_; 417 int pending_copy_operations_count_;
420 418
421 // This is set to false if any of the copyFile operations fail on 419 // This is set to false if any of the copyFile operations fail on
422 // call of the API. It is returned as a response of the API call. 420 // call of the API. It is returned as a response of the API call.
423 bool success_; 421 bool success_;
422 };
424 423
424 class DeveloperPrivateRequestFileSourceFunction
425 : public ChromeAsyncExtensionFunction {
426 public:
427 DECLARE_EXTENSION_FUNCTION("developerPrivate.requestFileSource",
428 DEVELOPERPRIVATE_REQUESTFILESOURCE);
429
430 DeveloperPrivateRequestFileSourceFunction();
431
432 protected:
433 virtual ~DeveloperPrivateRequestFileSourceFunction();
434
435 // ExtensionFunction
Dan Beam 2014/02/11 18:54:44 nit: // ExtensionFunction: or // ExtensionF
Devlin 2014/02/11 19:26:45 Whoops, done.
436 virtual bool RunImpl() OVERRIDE;
437
438 private:
439 void LaunchCallback(const base::DictionaryValue& results);
440 };
441
442 class DeveloperPrivateOpenDevToolsFunction
443 : public ChromeAsyncExtensionFunction {
444 public:
445 DECLARE_EXTENSION_FUNCTION("developerPrivate.openDevTools",
446 DEVELOPERPRIVATE_OPENDEVTOOLS);
447
448 DeveloperPrivateOpenDevToolsFunction();
449
450 protected:
451 virtual ~DeveloperPrivateOpenDevToolsFunction();
452
453 // ExtensionFunction
454 virtual bool RunImpl() OVERRIDE;
425 }; 455 };
426 456
427 } // namespace api 457 } // namespace api
428 458
429 } // namespace extensions 459 } // namespace extensions
430 460
431 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API _H_ 461 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698