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

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: 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 }
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 which have subscribed to the events,
82 // since we may treat events with these extensions differently.
83 std::set<std::string> extension_ids_;
84
73 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateEventRouter); 85 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateEventRouter);
74 }; 86 };
75 87
76 // The profile-keyed service that manages the DeveloperPrivate API. 88 // The profile-keyed service that manages the DeveloperPrivate API.
77 class DeveloperPrivateAPI : public BrowserContextKeyedService, 89 class DeveloperPrivateAPI : public BrowserContextKeyedService,
78 public extensions::EventRouter::Observer { 90 public EventRouter::Observer {
79 public: 91 public:
80 // Convenience method to get the DeveloperPrivateAPI for a profile. 92 // Convenience method to get the DeveloperPrivateAPI for a profile.
81 static DeveloperPrivateAPI* Get(Profile* profile); 93 static DeveloperPrivateAPI* Get(Profile* profile);
82 94
83 explicit DeveloperPrivateAPI(Profile* profile); 95 explicit DeveloperPrivateAPI(Profile* profile);
84 virtual ~DeveloperPrivateAPI(); 96 virtual ~DeveloperPrivateAPI();
85 97
86 void SetLastUnpackedDirectory(const base::FilePath& path); 98 void SetLastUnpackedDirectory(const base::FilePath& path);
87 99
88 base::FilePath& GetLastUnpackedDirectory() { 100 base::FilePath& GetLastUnpackedDirectory() {
89 return last_unpacked_directory_; 101 return last_unpacked_directory_;
90 } 102 }
91 103
92 // BrowserContextKeyedService implementation 104 // BrowserContextKeyedService implementation
93 virtual void Shutdown() OVERRIDE; 105 virtual void Shutdown() OVERRIDE;
94 106
95 // EventRouter::Observer implementation. 107 // EventRouter::Observer implementation.
96 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) 108 virtual void OnListenerAdded(const EventListenerInfo& details)
97 OVERRIDE; 109 OVERRIDE;
98 virtual void OnListenerRemoved(const extensions::EventListenerInfo& details) 110 virtual void OnListenerRemoved(const EventListenerInfo& details)
99 OVERRIDE; 111 OVERRIDE;
100 112
101 private: 113 private:
102 void RegisterNotifications(); 114 void RegisterNotifications();
103 115
104 Profile* profile_; 116 Profile* profile_;
105 117
106 // Used to start the load |load_extension_dialog_| in the last directory that 118 // Used to start the load |load_extension_dialog_| in the last directory that
107 // was loaded. 119 // was loaded.
108 base::FilePath last_unpacked_directory_; 120 base::FilePath last_unpacked_directory_;
(...skipping 27 matching lines...) Expand all
136 148
137 protected: 149 protected:
138 virtual ~DeveloperPrivateGetItemsInfoFunction(); 150 virtual ~DeveloperPrivateGetItemsInfoFunction();
139 151
140 // ExtensionFunction: 152 // ExtensionFunction:
141 virtual bool RunImpl() OVERRIDE; 153 virtual bool RunImpl() OVERRIDE;
142 154
143 private: 155 private:
144 156
145 scoped_ptr<developer::ItemInfo> CreateItemInfo( 157 scoped_ptr<developer::ItemInfo> CreateItemInfo(
146 const extensions::Extension& item, 158 const Extension& item, bool item_is_enabled);
147 bool item_is_enabled);
148 159
149 void GetIconsOnFileThread( 160 void GetIconsOnFileThread(
150 ItemInfoList item_list, 161 ItemInfoList item_list,
151 std::map<std::string, ExtensionResource> itemIdToIconResourceMap); 162 std::map<std::string, ExtensionResource> itemIdToIconResourceMap);
152 163
153 // Helper that lists the current inspectable html pages for the extension. 164 // Helper that lists the current inspectable html pages for the extension.
154 void GetInspectablePagesForExtensionProcess( 165 void GetInspectablePagesForExtensionProcess(
155 const Extension* extension, 166 const Extension* extension,
156 const std::set<content::RenderViewHost*>& views, 167 const std::set<content::RenderViewHost*>& views,
157 ItemInspectViewList* result); 168 ItemInspectViewList* result);
158 169
159 ItemInspectViewList GetInspectablePagesForExtension( 170 ItemInspectViewList GetInspectablePagesForExtension(
160 const extensions::Extension* extension, 171 const Extension* extension, bool extension_is_enabled);
161 bool extension_is_enabled);
162 172
163 void GetShellWindowPagesForExtensionProfile( 173 void GetShellWindowPagesForExtensionProfile(
164 const extensions::Extension* extension, 174 const Extension* extension, ItemInspectViewList* result);
165 ItemInspectViewList* result);
166 175
167 linked_ptr<developer::ItemInspectView> constructInspectView( 176 linked_ptr<developer::ItemInspectView> constructInspectView(
168 const GURL& url, 177 const GURL& url,
169 int render_process_id, 178 int render_process_id,
170 int render_view_id, 179 int render_view_id,
171 bool incognito, 180 bool incognito,
172 bool generated_background_page); 181 bool generated_background_page);
173 }; 182 };
174 183
175 class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction { 184 class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 protected: 266 protected:
258 virtual ~DeveloperPrivateEnableFunction(); 267 virtual ~DeveloperPrivateEnableFunction();
259 268
260 // Callback for requirements checker. 269 // Callback for requirements checker.
261 void OnRequirementsChecked(std::string extension_id, 270 void OnRequirementsChecked(std::string extension_id,
262 std::vector<std::string> requirements_errors); 271 std::vector<std::string> requirements_errors);
263 // ExtensionFunction: 272 // ExtensionFunction:
264 virtual bool RunImpl() OVERRIDE; 273 virtual bool RunImpl() OVERRIDE;
265 274
266 private: 275 private:
267 scoped_ptr<extensions::RequirementsChecker> requirements_checker_; 276 scoped_ptr<RequirementsChecker> requirements_checker_;
268 }; 277 };
269 278
270 class DeveloperPrivateChooseEntryFunction : public ChromeAsyncExtensionFunction, 279 class DeveloperPrivateChooseEntryFunction : public ChromeAsyncExtensionFunction,
271 public EntryPickerClient { 280 public EntryPickerClient {
272 protected: 281 protected:
273 virtual ~DeveloperPrivateChooseEntryFunction(); 282 virtual ~DeveloperPrivateChooseEntryFunction();
274 virtual bool RunImpl() OVERRIDE; 283 virtual bool RunImpl() OVERRIDE;
275 bool ShowPicker(ui::SelectFileDialog::Type picker_type, 284 bool ShowPicker(ui::SelectFileDialog::Type picker_type,
276 const base::FilePath& last_directory, 285 const base::FilePath& last_directory,
277 const base::string16& select_title, 286 const base::string16& select_title,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 virtual ~DeveloperPrivateChoosePathFunction(); 318 virtual ~DeveloperPrivateChoosePathFunction();
310 virtual bool RunImpl() OVERRIDE; 319 virtual bool RunImpl() OVERRIDE;
311 320
312 // EntryPickerClient functions. 321 // EntryPickerClient functions.
313 virtual void FileSelected(const base::FilePath& path) OVERRIDE; 322 virtual void FileSelected(const base::FilePath& path) OVERRIDE;
314 virtual void FileSelectionCanceled() OVERRIDE; 323 virtual void FileSelectionCanceled() OVERRIDE;
315 }; 324 };
316 325
317 class DeveloperPrivatePackDirectoryFunction 326 class DeveloperPrivatePackDirectoryFunction
318 : public ChromeAsyncExtensionFunction, 327 : public ChromeAsyncExtensionFunction,
319 public extensions::PackExtensionJob::Client { 328 public PackExtensionJob::Client {
320 329
321 public: 330 public:
322 DECLARE_EXTENSION_FUNCTION("developerPrivate.packDirectory", 331 DECLARE_EXTENSION_FUNCTION("developerPrivate.packDirectory",
323 DEVELOPERPRIVATE_PACKDIRECTORY); 332 DEVELOPERPRIVATE_PACKDIRECTORY);
324 333
325 DeveloperPrivatePackDirectoryFunction(); 334 DeveloperPrivatePackDirectoryFunction();
326 335
327 // ExtensionPackJob::Client implementation. 336 // ExtensionPackJob::Client implementation.
328 virtual void OnPackSuccess(const base::FilePath& crx_file, 337 virtual void OnPackSuccess(const base::FilePath& crx_file,
329 const base::FilePath& key_file) OVERRIDE; 338 const base::FilePath& key_file) OVERRIDE;
330 virtual void OnPackFailure( 339 virtual void OnPackFailure(
331 const std::string& error, 340 const std::string& error,
332 extensions::ExtensionCreator::ErrorType error_type) OVERRIDE; 341 ExtensionCreator::ErrorType error_type) OVERRIDE;
333 342
334 protected: 343 protected:
335 virtual ~DeveloperPrivatePackDirectoryFunction(); 344 virtual ~DeveloperPrivatePackDirectoryFunction();
336 virtual bool RunImpl() OVERRIDE; 345 virtual bool RunImpl() OVERRIDE;
337 346
338 private: 347 private:
339 scoped_refptr<extensions::PackExtensionJob> pack_job_; 348 scoped_refptr<PackExtensionJob> pack_job_;
340 std::string item_path_str_; 349 std::string item_path_str_;
341 std::string key_path_str_; 350 std::string key_path_str_;
342 }; 351 };
343 352
344 class DeveloperPrivateGetStringsFunction : public ChromeSyncExtensionFunction { 353 class DeveloperPrivateGetStringsFunction : public ChromeSyncExtensionFunction {
345 public: 354 public:
346 DECLARE_EXTENSION_FUNCTION("developerPrivate.getStrings", 355 DECLARE_EXTENSION_FUNCTION("developerPrivate.getStrings",
347 DEVELOPERPRIVATE_GETSTRINGS); 356 DEVELOPERPRIVATE_GETSTRINGS);
348 357
349 protected: 358 protected:
350 virtual ~DeveloperPrivateGetStringsFunction(); 359 virtual ~DeveloperPrivateGetStringsFunction();
351 360
352 // ExtensionFunction 361 // ExtensionFunction
353 virtual bool RunImpl() OVERRIDE; 362 virtual bool RunImpl() OVERRIDE;
354 }; 363 };
355 364
356 class DeveloperPrivateIsProfileManagedFunction 365 class DeveloperPrivateIsProfileManagedFunction
357 : public ChromeSyncExtensionFunction { 366 : public ChromeSyncExtensionFunction {
358 public: 367 public:
359 DECLARE_EXTENSION_FUNCTION("developerPrivate.isProfileManaged", 368 DECLARE_EXTENSION_FUNCTION("developerPrivate.isProfileManaged",
360 DEVELOPERPRIVATE_ISPROFILEMANAGED); 369 DEVELOPERPRIVATE_ISPROFILEMANAGED);
361 370
362 protected: 371 protected:
363 virtual ~DeveloperPrivateIsProfileManagedFunction(); 372 virtual ~DeveloperPrivateIsProfileManagedFunction();
364 373
365 // ExtensionFunction 374 // ExtensionFunction
366 virtual bool RunImpl() OVERRIDE; 375 virtual bool RunImpl() OVERRIDE;
367 }; 376 };
368 377
369 class DeveloperPrivateLoadDirectoryFunction 378 class DeveloperPrivateLoadDirectoryFunction
370 : public ChromeAsyncExtensionFunction { 379 : public ChromeAsyncExtensionFunction {
371 public: 380 public:
372 DECLARE_EXTENSION_FUNCTION("developerPrivate.loadDirectory", 381 DECLARE_EXTENSION_FUNCTION("developerPrivate.loadDirectory",
373 DEVELOPERPRIVATE_LOADUNPACKEDCROS); 382 DEVELOPERPRIVATE_LOADUNPACKEDCROS);
374 383
375 DeveloperPrivateLoadDirectoryFunction(); 384 DeveloperPrivateLoadDirectoryFunction();
376 385
377 protected: 386 protected:
378 virtual ~DeveloperPrivateLoadDirectoryFunction(); 387 virtual ~DeveloperPrivateLoadDirectoryFunction();
379 388
380 // ExtensionFunction 389 // ExtensionFunction
381 virtual bool RunImpl() OVERRIDE; 390 virtual bool RunImpl() OVERRIDE;
382 391
383 void ClearExistingDirectoryContent(const base::FilePath& project_path); 392 void ClearExistingDirectoryContent(const base::FilePath& project_path);
384 393
385 void ReadSyncFileSystemDirectory(const base::FilePath& project_path, 394 void ReadSyncFileSystemDirectory(const base::FilePath& project_path,
386 const base::FilePath& destination_path); 395 const base::FilePath& destination_path);
387 396
388 void ReadSyncFileSystemDirectoryCb( 397 void ReadSyncFileSystemDirectoryCb(
389 const base::FilePath& project_path, 398 const base::FilePath& project_path,
390 const base::FilePath& destination_path, 399 const base::FilePath& destination_path,
391 base::File::Error result, 400 base::File::Error result,
392 const fileapi::FileSystemOperation::FileEntryList& file_list, 401 const fileapi::FileSystemOperation::FileEntryList& file_list,
393 bool has_more); 402 bool has_more);
394 403
395 void SnapshotFileCallback( 404 void SnapshotFileCallback(
396 const base::FilePath& target_path, 405 const base::FilePath& target_path,
397 base::File::Error result, 406 base::File::Error result,
398 const base::File::Info& file_info, 407 const base::File::Info& file_info,
399 const base::FilePath& platform_path, 408 const base::FilePath& platform_path,
400 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); 409 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
401 410
402 void CopyFile(const base::FilePath& src_path, 411 void CopyFile(const base::FilePath& src_path,
403 const base::FilePath& dest_path); 412 const base::FilePath& dest_path);
404 413
405 void Load(); 414 void Load();
406 415
407 scoped_refptr<fileapi::FileSystemContext> context_; 416 scoped_refptr<fileapi::FileSystemContext> context_;
408 417
409 // syncfs url representing the root of the folder to be copied. 418 // syncfs url representing the root of the folder to be copied.
410 std::string project_base_url_; 419 std::string project_base_url_;
411 420
412 // physical path on disc of the folder to be copied. 421 // physical path on disc of the folder to be copied.
413 base::FilePath project_base_path_; 422 base::FilePath project_base_path_;
414 423
415 // Path of the current folder to be copied. 424 // Path of the current folder to be copied.
416 base::FilePath current_path_; 425 base::FilePath current_path_;
417 426
418 private: 427 private:
419 int pending_copy_operations_count_; 428 int pending_copy_operations_count_;
420 429
421 // This is set to false if any of the copyFile operations fail on 430 // 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. 431 // call of the API. It is returned as a response of the API call.
423 bool success_; 432 bool success_;
433 };
424 434
435 class DeveloperPrivateRequestFileSourceFunction
436 : public ChromeAsyncExtensionFunction {
437 public:
438 DECLARE_EXTENSION_FUNCTION("developerPrivate.requestFileSource",
439 DEVELOPERPRIVATE_REQUESTFILESOURCE);
440
441 DeveloperPrivateRequestFileSourceFunction();
442
443 protected:
444 virtual ~DeveloperPrivateRequestFileSourceFunction();
445
446 // ExtensionFunction
447 virtual bool RunImpl() OVERRIDE;
448
449 private:
450 void LaunchCallback(const base::DictionaryValue& results);
451 };
452
453 class DeveloperPrivateOpenDevToolsFunction
454 : public ChromeAsyncExtensionFunction {
455 public:
456 DECLARE_EXTENSION_FUNCTION("developerPrivate.openDevTools",
457 DEVELOPERPRIVATE_OPENDEVTOOLS);
458
459 DeveloperPrivateOpenDevToolsFunction();
460
461 protected:
462 virtual ~DeveloperPrivateOpenDevToolsFunction();
463
464 // ExtensionFunction
465 virtual bool RunImpl() OVERRIDE;
425 }; 466 };
426 467
427 } // namespace api 468 } // namespace api
428 469
429 } // namespace extensions 470 } // namespace extensions
430 471
431 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API _H_ 472 #endif // CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698