OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 // Returns the base extension url for a given |extension_id|. | 301 // Returns the base extension url for a given |extension_id|. |
302 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 302 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
303 | 303 |
304 // Returns the url prefix for the extension/apps gallery. Can be set via the | 304 // Returns the url prefix for the extension/apps gallery. Can be set via the |
305 // --apps-gallery-url switch. The URL returned will not contain a trailing | 305 // --apps-gallery-url switch. The URL returned will not contain a trailing |
306 // slash. Do not use this as a prefix/extent for the store. Instead see | 306 // slash. Do not use this as a prefix/extent for the store. Instead see |
307 // ExtensionService::GetWebStoreApp or | 307 // ExtensionService::GetWebStoreApp or |
308 // ExtensionService::IsDownloadFromGallery | 308 // ExtensionService::IsDownloadFromGallery |
309 static std::string ChromeStoreLaunchURL(); | 309 static std::string ChromeStoreLaunchURL(); |
310 | 310 |
311 // Helper function that consolidates the check for whether the script can | |
312 // execute into one location. |page_url| is the page that is the candidate | |
313 // for running the script, |can_execute_script_everywhere| specifies whether | |
314 // the extension is on the whitelist, |allowed_pages| is a vector of | |
315 // URLPatterns, listing what access the extension has, |script| is the script | |
316 // pointer (if content script) and |error| is an optional parameter, which | |
317 // will receive the error string listing why access was denied. | |
318 static bool CanExecuteScriptOnPage( | |
319 const GURL& page_url, | |
320 bool can_execute_script_everywhere, | |
321 const std::vector<URLPattern>* allowed_pages, | |
322 UserScript* script, | |
323 std::string* error); | |
324 | |
325 // Adds an extension to the scripting whitelist. Used for testing only. | 311 // Adds an extension to the scripting whitelist. Used for testing only. |
326 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 312 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
327 | 313 |
328 // Returns true if the extension has the specified API permission. | 314 // Returns true if the extension has the specified API permission. |
329 static bool HasApiPermission(const std::set<std::string>& api_permissions, | 315 static bool HasApiPermission(const std::set<std::string>& api_permissions, |
330 const std::string& function_name); | 316 const std::string& function_name); |
331 | 317 |
332 // Whether the |effective_host_permissions| and |api_permissions| include | 318 // Whether the |effective_host_permissions| and |api_permissions| include |
333 // effective access to all hosts. See the non-static version of the method | 319 // effective access to all hosts. See the non-static version of the method |
334 // for more details. | 320 // for more details. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 // the browser might load (like themes and page action icons). | 359 // the browser might load (like themes and page action icons). |
374 std::set<FilePath> GetBrowserImages() const; | 360 std::set<FilePath> GetBrowserImages() const; |
375 | 361 |
376 // Get an extension icon as a resource or URL. | 362 // Get an extension icon as a resource or URL. |
377 ExtensionResource GetIconResource( | 363 ExtensionResource GetIconResource( |
378 int size, ExtensionIconSet::MatchType match_type) const; | 364 int size, ExtensionIconSet::MatchType match_type) const; |
379 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; | 365 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; |
380 | 366 |
381 // Gets the fully resolved absolute launch URL. | 367 // Gets the fully resolved absolute launch URL. |
382 GURL GetFullLaunchURL() const; | 368 GURL GetFullLaunchURL() const; |
| 369 |
383 // Image cache related methods. These are only valid on the UI thread and | 370 // Image cache related methods. These are only valid on the UI thread and |
384 // not maintained by this class. See ImageLoadingTracker for usage. The | 371 // not maintained by this class. See ImageLoadingTracker for usage. The |
385 // |original_size| parameter should be the size of the image at |source| | 372 // |original_size| parameter should be the size of the image at |source| |
386 // before any scaling may have been done to produce the pixels in |image|. | 373 // before any scaling may have been done to produce the pixels in |image|. |
387 void SetCachedImage(const ExtensionResource& source, | 374 void SetCachedImage(const ExtensionResource& source, |
388 const SkBitmap& image, | 375 const SkBitmap& image, |
389 const gfx::Size& original_size) const; | 376 const gfx::Size& original_size) const; |
390 bool HasCachedImage(const ExtensionResource& source, | 377 bool HasCachedImage(const ExtensionResource& source, |
391 const gfx::Size& max_size) const; | 378 const gfx::Size& max_size) const; |
392 SkBitmap GetCachedImage(const ExtensionResource& source, | 379 SkBitmap GetCachedImage(const ExtensionResource& source, |
393 const gfx::Size& max_size) const; | 380 const gfx::Size& max_size) const; |
| 381 |
| 382 // Returns true if this extension can execute script on a page. If a |
| 383 // UserScript object is passed, permission to run that specific script is |
| 384 // checked (using its matches list). Otherwise, permission to execute script |
| 385 // programmatically is checked (using the extension's host permission). |
| 386 // |
| 387 // This method is also aware of certain special pages that extensions are |
| 388 // usually not allowed to run script on. |
| 389 bool CanExecuteScriptOnPage(const GURL& page_url, |
| 390 UserScript* script, |
| 391 std::string* error) const; |
| 392 |
394 // Returns true if this extension is a COMPONENT extension, or if it is | 393 // Returns true if this extension is a COMPONENT extension, or if it is |
395 // on the whitelist of extensions that can script all pages. | 394 // on the whitelist of extensions that can script all pages. |
396 bool CanExecuteScriptEverywhere() const; | 395 bool CanExecuteScriptEverywhere() const; |
397 | 396 |
398 // Returns true if this extension updates itself using the extension | 397 // Returns true if this extension updates itself using the extension |
399 // gallery. | 398 // gallery. |
400 bool UpdatesFromGallery() const; | 399 bool UpdatesFromGallery() const; |
401 | 400 |
402 // Accessors: | 401 // Accessors: |
403 | 402 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 // Was the extension already disabled? | 768 // Was the extension already disabled? |
770 bool already_disabled; | 769 bool already_disabled; |
771 | 770 |
772 // The extension being unloaded - this should always be non-NULL. | 771 // The extension being unloaded - this should always be non-NULL. |
773 const Extension* extension; | 772 const Extension* extension; |
774 | 773 |
775 UnloadedExtensionInfo(const Extension* extension, Reason reason); | 774 UnloadedExtensionInfo(const Extension* extension, Reason reason); |
776 }; | 775 }; |
777 | 776 |
778 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 777 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |