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

Side by Side Diff: chrome/common/extensions/extension.h

Issue 14651017: Move RuntimeData and related permissions out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_permissions
Patch Set: Created 7 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_COMMON_EXTENSIONS_EXTENSION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <map> 10 #include <map>
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 std::string* output, 240 std::string* output,
241 bool is_public); 241 bool is_public);
242 242
243 // Returns the base extension url for a given |extension_id|. 243 // Returns the base extension url for a given |extension_id|.
244 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); 244 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
245 245
246 // Adds an extension to the scripting whitelist. Used for testing only. 246 // Adds an extension to the scripting whitelist. Used for testing only.
247 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); 247 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
248 static const ScriptingWhitelist* GetScriptingWhitelist(); 248 static const ScriptingWhitelist* GetScriptingWhitelist();
249 249
250 // Returns true if this extension has the given permission. Prefer 250 // Do Not Use: These methods have been moved to PermissionsData.
Yoyo Zhou 2013/05/11 00:57:04 s/Do Not Use/DEPRECATED/
Devlin 2013/05/13 22:44:23 Done.
251 // IsExtensionWithPermissionOrSuggestInConsole when developers may be using an 251 // TODO(rdevlin.cronin): remove these once all calls have been updated.
252 // api that requires a permission they didn't know about, e.g. open web apis.
253 bool HasAPIPermission(APIPermission::ID permission) const; 252 bool HasAPIPermission(APIPermission::ID permission) const;
254 bool HasAPIPermission(const std::string& function_name) const; 253 bool HasAPIPermission(const std::string& function_name) const;
255 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const;
256
257 bool CheckAPIPermissionWithParam(
258 APIPermission::ID permission,
259 const APIPermission::CheckParam* param) const;
260
261 const URLPatternSet& GetEffectiveHostPermissions() const;
262
263 // Returns true if the extension can silently increase its permission level.
264 // Users must approve permissions for unpacked and packed extensions in the
265 // following situations:
266 // - when installing or upgrading packed extensions
267 // - when installing unpacked extensions that have NPAPI plugins
268 // - when either type of extension requests optional permissions
269 bool CanSilentlyIncreasePermissions() const;
270
271 // Whether the extension has access to the given URL.
272 bool HasHostPermission(const GURL& url) const;
273
274 // Whether the extension has effective access to all hosts. This is true if
275 // there is a content script that matches all hosts, if there is a host
276 // permission grants access to all hosts (like <all_urls>) or an api
277 // permission that effectively grants access to all hosts (e.g. proxy,
278 // network, etc.)
279 bool HasEffectiveAccessToAllHosts() const;
280
281 // Whether the extension effectively has all permissions (for example, by
282 // having an NPAPI plugin).
283 bool HasFullPermissions() const;
284
285 // Returns the full list of permission messages that this extension
286 // should display at install time.
287 PermissionMessages GetPermissionMessages() const;
288
289 // Returns the full list of permission messages that this extension
290 // should display at install time. The messages are returned as strings
291 // for convenience.
292 std::vector<string16> GetPermissionMessageStrings() const;
293
294 // Returns true if the extension does not require permission warnings
295 // to be displayed at install time.
296 bool ShouldSkipPermissionWarnings() const;
297
298 // Sets the active |permissions|.
299 void SetActivePermissions(const PermissionSet* permissions) const;
300
301 // Gets the extension's active permission set.
302 scoped_refptr<const PermissionSet> GetActivePermissions() const; 254 scoped_refptr<const PermissionSet> GetActivePermissions() const;
303 255
304 // Whether context menu should be shown for page and browser actions. 256 // Whether context menu should be shown for page and browser actions.
305 bool ShowConfigureContextMenus() const; 257 bool ShowConfigureContextMenus() const;
306 258
307 // Gets the fully resolved absolute launch URL. 259 // Gets the fully resolved absolute launch URL.
308 GURL GetFullLaunchURL() const; 260 GURL GetFullLaunchURL() const;
309 261
310 // Returns true if this extension can execute script on a page. If a
311 // UserScript object is passed, permission to run that specific script is
312 // checked (using its matches list). Otherwise, permission to execute script
313 // programmatically is checked (using the extension's host permission).
314 //
315 // This method is also aware of certain special pages that extensions are
316 // usually not allowed to run script on.
317 bool CanExecuteScriptOnPage(const GURL& document_url,
318 const GURL& top_document_url,
319 int tab_id,
320 const UserScript* script,
321 std::string* error) const;
322
323 // Returns true if this extension is a COMPONENT extension, or if it is
324 // on the whitelist of extensions that can script all pages.
325 bool CanExecuteScriptEverywhere() const;
326
327 // Returns true if this extension is allowed to obtain the contents of a
328 // page as an image. Since a page may contain sensitive information, this
329 // is restricted to the extension's host permissions as well as the
330 // extension page itself.
331 bool CanCaptureVisiblePage(const GURL& page_url,
332 int tab_id,
333 std::string* error) const;
334
335 // Returns true if this extension updates itself using the extension 262 // Returns true if this extension updates itself using the extension
336 // gallery. 263 // gallery.
337 bool UpdatesFromGallery() const; 264 bool UpdatesFromGallery() const;
338 265
339 // Returns true if this extension or app includes areas within |origin|. 266 // Returns true if this extension or app includes areas within |origin|.
340 bool OverlapsWithOrigin(const GURL& origin) const; 267 bool OverlapsWithOrigin(const GURL& origin) const;
341 268
342 // Returns the sync bucket to use for this extension. 269 // Returns the sync bucket to use for this extension.
343 SyncType GetSyncType() const; 270 SyncType GetSyncType() const;
344 271
345 // Returns true if the extension should be synced. 272 // Returns true if the extension should be synced.
346 bool IsSyncable() const; 273 bool IsSyncable() const;
347 274
275 // Returns true if this extension id is from a trusted provider.
276 static bool IsTrustedId(const std::string& id);
277
348 // Returns true if the extension requires a valid ordinal for sorting, e.g., 278 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
349 // for displaying in a launcher or new tab page. 279 // for displaying in a launcher or new tab page.
350 bool RequiresSortOrdinal() const; 280 bool RequiresSortOrdinal() const;
351 281
352 // Returns true if the extension should be displayed in the app launcher. 282 // Returns true if the extension should be displayed in the app launcher.
353 bool ShouldDisplayInAppLauncher() const; 283 bool ShouldDisplayInAppLauncher() const;
354 284
355 // Returns true if the extension should be displayed in the browser NTP. 285 // Returns true if the extension should be displayed in the browser NTP.
356 bool ShouldDisplayInNewTabPage() const; 286 bool ShouldDisplayInNewTabPage() const;
357 287
358 // Returns true if the extension should be displayed in the extension 288 // Returns true if the extension should be displayed in the extension
359 // settings page (i.e. chrome://extensions). 289 // settings page (i.e. chrome://extensions).
360 bool ShouldDisplayInExtensionSettings() const; 290 bool ShouldDisplayInExtensionSettings() const;
361 291
362 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
363 // aren't any.
364 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
365 const;
366
367 // Updates the tab-specific permissions of |tab_id| to include those from
368 // |permissions|.
369 void UpdateTabSpecificPermissions(
370 int tab_id,
371 scoped_refptr<const PermissionSet> permissions) const;
372
373 // Clears the tab-specific permissions of |tab_id|.
374 void ClearTabSpecificPermissions(int tab_id) const;
375
376 // Get the manifest data associated with the key, or NULL if there is none. 292 // Get the manifest data associated with the key, or NULL if there is none.
377 // Can only be called after InitValue is finished. 293 // Can only be called after InitValue is finished.
378 ManifestData* GetManifestData(const std::string& key) const; 294 ManifestData* GetManifestData(const std::string& key) const;
379 295
380 // Sets |data| to be associated with the key. Takes ownership of |data|. 296 // Sets |data| to be associated with the key. Takes ownership of |data|.
381 // Can only be called before InitValue is finished. Not thread-safe; 297 // Can only be called before InitValue is finished. Not thread-safe;
382 // all SetManifestData calls should be on only one thread. 298 // all SetManifestData calls should be on only one thread.
383 void SetManifestData(const std::string& key, ManifestData* data); 299 void SetManifestData(const std::string& key, ManifestData* data);
384 300
385 // Accessors: 301 // Accessors:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 364 }
449 int launch_width() const { return launch_width_; } 365 int launch_width() const { return launch_width_; }
450 int launch_height() const { return launch_height_; } 366 int launch_height() const { return launch_height_; }
451 367
452 // Theme-related. 368 // Theme-related.
453 bool is_theme() const; 369 bool is_theme() const;
454 370
455 private: 371 private:
456 friend class base::RefCountedThreadSafe<Extension>; 372 friend class base::RefCountedThreadSafe<Extension>;
457 373
458 class RuntimeData {
459 public:
460 RuntimeData();
461 explicit RuntimeData(const PermissionSet* active);
462 ~RuntimeData();
463
464 void SetActivePermissions(const PermissionSet* active);
465 scoped_refptr<const PermissionSet> GetActivePermissions() const;
466
467 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
468 const;
469 void UpdateTabSpecificPermissions(
470 int tab_id,
471 scoped_refptr<const PermissionSet> permissions);
472 void ClearTabSpecificPermissions(int tab_id);
473
474 private:
475 friend class base::RefCountedThreadSafe<RuntimeData>;
476
477 scoped_refptr<const PermissionSet> active_permissions_;
478
479 typedef std::map<int, scoped_refptr<const PermissionSet> >
480 TabPermissionsMap;
481 TabPermissionsMap tab_specific_permissions_;
482 };
483
484 // Chooses the extension ID for an extension based on a variety of criteria. 374 // Chooses the extension ID for an extension based on a variety of criteria.
485 // The chosen ID will be set in |manifest|. 375 // The chosen ID will be set in |manifest|.
486 static bool InitExtensionID(extensions::Manifest* manifest, 376 static bool InitExtensionID(extensions::Manifest* manifest,
487 const base::FilePath& path, 377 const base::FilePath& path,
488 const std::string& explicit_id, 378 const std::string& explicit_id,
489 int creation_flags, 379 int creation_flags,
490 string16* error); 380 string16* error);
491 381
492 // Returns true if this extension id is from a trusted provider.
493 static bool IsTrustedId(const std::string& id);
494
495 Extension(const base::FilePath& path, 382 Extension(const base::FilePath& path,
496 scoped_ptr<extensions::Manifest> manifest); 383 scoped_ptr<extensions::Manifest> manifest);
497 virtual ~Extension(); 384 virtual ~Extension();
498 385
499 // Initialize the extension from a parsed manifest. 386 // Initialize the extension from a parsed manifest.
500 // TODO(aa): Rename to just Init()? There's no Value here anymore. 387 // TODO(aa): Rename to just Init()? There's no Value here anymore.
501 // TODO(aa): It is really weird the way this class essentially contains a copy 388 // TODO(aa): It is really weird the way this class essentially contains a copy
502 // of the underlying DictionaryValue in its members. We should decide to 389 // of the underlying DictionaryValue in its members. We should decide to
503 // either wrap the DictionaryValue and go with that only, or we should parse 390 // either wrap the DictionaryValue and go with that only, or we should parse
504 // into strong types and discard the value. But doing both is bad. 391 // into strong types and discard the value. But doing both is bad.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // this member variable to 0 to distinguish the "uninitialized" case from 447 // this member variable to 0 to distinguish the "uninitialized" case from
561 // the case when we know the manifest version actually is 1. 448 // the case when we know the manifest version actually is 1.
562 int manifest_version_; 449 int manifest_version_;
563 450
564 // The absolute path to the directory the extension is stored in. 451 // The absolute path to the directory the extension is stored in.
565 base::FilePath path_; 452 base::FilePath path_;
566 453
567 // Defines the set of URLs in the extension's web content. 454 // Defines the set of URLs in the extension's web content.
568 URLPatternSet extent_; 455 URLPatternSet extent_;
569 456
570 // The extension runtime data.
571 mutable base::Lock runtime_data_lock_;
572 mutable RuntimeData runtime_data_;
573
574 scoped_ptr<PermissionsData> permissions_data_; 457 scoped_ptr<PermissionsData> permissions_data_;
575 458
576 // Any warnings that occurred when trying to create/parse the extension. 459 // Any warnings that occurred when trying to create/parse the extension.
577 std::vector<InstallWarning> install_warnings_; 460 std::vector<InstallWarning> install_warnings_;
578 461
579 // The base extension url for the extension. 462 // The base extension url for the extension.
580 GURL extension_url_; 463 GURL extension_url_;
581 464
582 // The extension's version. 465 // The extension's version.
583 scoped_ptr<base::Version> version_; 466 scoped_ptr<base::Version> version_;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 592
710 UpdatedExtensionPermissionsInfo( 593 UpdatedExtensionPermissionsInfo(
711 const Extension* extension, 594 const Extension* extension,
712 const PermissionSet* permissions, 595 const PermissionSet* permissions,
713 Reason reason); 596 Reason reason);
714 }; 597 };
715 598
716 } // namespace extensions 599 } // namespace extensions
717 600
718 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 601 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698