OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_CHROME_PLUGIN_UTIL_H_ | 5 #ifndef CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ |
6 #define CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ | 6 #define CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 void* data; | 35 void* data; |
36 }; | 36 }; |
37 | 37 |
38 // This is a base class for plugin-related objects that need to go away when | 38 // This is a base class for plugin-related objects that need to go away when |
39 // the plugin unloads. This object also verifies that it is created and | 39 // the plugin unloads. This object also verifies that it is created and |
40 // destroyed on the same thread. | 40 // destroyed on the same thread. |
41 class PluginHelper : public NotificationObserver, public NonThreadSafe { | 41 class PluginHelper : public NotificationObserver, public NonThreadSafe { |
42 public: | 42 public: |
43 static void DestroyAllHelpersForPlugin(ChromePluginLib* plugin); | 43 static void DestroyAllHelpersForPlugin(ChromePluginLib* plugin); |
44 | 44 |
45 PluginHelper(ChromePluginLib* plugin); | 45 explicit PluginHelper(ChromePluginLib* plugin); |
46 virtual ~PluginHelper(); | 46 virtual ~PluginHelper(); |
47 | 47 |
48 // NotificationObserver | 48 // NotificationObserver |
49 virtual void Observe(NotificationType type, | 49 virtual void Observe(NotificationType type, |
50 const NotificationSource& source, | 50 const NotificationSource& source, |
51 const NotificationDetails& details); | 51 const NotificationDetails& details); |
52 | 52 |
53 protected: | 53 protected: |
54 NotificationRegistrar registrar_; | 54 NotificationRegistrar registrar_; |
55 | 55 |
56 scoped_refptr<ChromePluginLib> plugin_; | 56 scoped_refptr<ChromePluginLib> plugin_; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(PluginHelper); | 58 DISALLOW_COPY_AND_ASSIGN(PluginHelper); |
59 }; | 59 }; |
60 | 60 |
61 // A class of utility functions for dealing with request responses. | 61 // A class of utility functions for dealing with request responses. |
62 class PluginResponseUtils { | 62 class PluginResponseUtils { |
63 public: | 63 public: |
64 // Helper to convert request load flags from the plugin API to the net API | 64 // Helper to convert request load flags from the plugin API to the net API |
65 // versions. | 65 // versions. |
66 static uint32 CPLoadFlagsToNetFlags(uint32 flags); | 66 static uint32 CPLoadFlagsToNetFlags(uint32 flags); |
67 | 67 |
68 // Common implementation of a CPR_GetResponseInfo call. | 68 // Common implementation of a CPR_GetResponseInfo call. |
69 static int GetResponseInfo( | 69 static int GetResponseInfo( |
70 const net::HttpResponseHeaders* response_headers, | 70 const net::HttpResponseHeaders* response_headers, |
71 CPResponseInfoType type, void* buf, size_t buf_size); | 71 CPResponseInfoType type, void* buf, size_t buf_size); |
72 }; | 72 }; |
73 | 73 |
74 // Helper to allocate a string using the given CPB_Alloc function. | 74 // Helper to allocate a string using the given CPB_Alloc function. |
75 inline char* CPB_StringDup(CPB_AllocFunc alloc, const std::string& str) { | 75 inline char* CPB_StringDup(CPB_AllocFunc alloc, const std::string& str) { |
76 char* cstr = static_cast<char*>(alloc(static_cast<uint32>(str.length() + 1))); | 76 char* cstr = static_cast<char*>(alloc(static_cast<uint32>(str.length() + 1))); |
77 memcpy(cstr, str.c_str(), str.length() + 1); // Include null terminator. | 77 memcpy(cstr, str.c_str(), str.length() + 1); // Include null terminator. |
78 return cstr; | 78 return cstr; |
79 } | 79 } |
80 | 80 |
81 CPError CPB_GetCommandLineArgumentsCommon(const char* url, | 81 CPError CPB_GetCommandLineArgumentsCommon(const char* url, |
82 std::string* arguments); | 82 std::string* arguments); |
83 | 83 |
84 void* STDCALL CPB_Alloc(uint32 size); | 84 void* STDCALL CPB_Alloc(uint32 size); |
85 void STDCALL CPB_Free(void* memory); | 85 void STDCALL CPB_Free(void* memory); |
86 | 86 |
87 #endif // CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ | 87 #endif // CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ |
OLD | NEW |