Hello andreip,

I'd like you to do a code review.  Please execute
        g4 diff -c 9135600

or point your web browser to
        http://mondrian/9135600

to review the following code:

Change 9135600 by [EMAIL PROTECTED] on 2008/11/24 16:53:02 *pending*

        Adds the Opera Mobile browser API headers and the OperaUtils class for 
accessing this API.
        
        R=andreip
        [EMAIL PROTECTED],[email protected]
        DELTA=290  (290 added, 0 deleted, 0 changed)
        OCL=9135600

Affected files ...

... 
//depot/googleclient/gears/opensource/third_party/opera/opera_callback_api.h#1 
add
... 
//depot/googleclient/gears/opensource/third_party/opera/opera_local_server_interface.h#1
 add
... 
//depot/googleclient/gears/opensource/third_party/opera/opera_worker_interface.h#1
 add

290 delta lines: 290 added, 0 deleted, 0 changed

Also consider running:
        g4 lint -c 9135600

which verifies that the changelist doesn't introduce new style violations.

If you can't do the review, please let me know as soon as possible.  During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately.  Visit
http://www/eng/code_review.html for more information.

This is a semiautomated message from "g4 mail".  Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 9135600 by [EMAIL PROTECTED] on 2008/11/24 16:53:02 *pending*

        Adds the Opera Mobile browser API headers and the OperaUtils class for 
accessing this API.
        
        R=andreip
        [EMAIL PROTECTED],[email protected]
        DELTA=288  (288 added, 0 deleted, 0 changed)
        OCL=9135600

Affected files ...

... 
//depot/googleclient/gears/opensource/third_party/opera/opera_callback_api.h#1 
add
... 
//depot/googleclient/gears/opensource/third_party/opera/opera_local_server_interface.h#1
 add
... 
//depot/googleclient/gears/opensource/third_party/opera/opera_worker_interface.h#1
 add

==== 
//depot/googleclient/gears/opensource/third_party/opera/opera_callback_api.h#1 
- 
c:\MyDocs\Gears3/googleclient/gears/opensource/third_party/opera/opera_callback_api.h
 ====
# action=add type=text
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/third_party/opera/opera_callback_api.h        
2008-12-10 17:05:21.000000000 +0000
@@ -0,0 +1,194 @@
+// This file is used by both Opera and the Gears code as a common API
+// between the two code bases.
+
+#ifndef OPERA_CALLBACK_API_H__
+#define OPERA_CALLBACK_API_H__
+
+// EXTERNAL_GEARS_SUPPORT is set whe nthis file is included by the Opera
+// browser.
+#ifdef EXTERNAL_GEARS_SUPPORT
+#include "modules/ns4plugins/src/plug-inc/npapi.h"  // for NPP for Opera
+#else
+#include "third_party/npapi/npapi.h"  // for NPP for Gears
+#endif
+
+struct NPObject;
+struct OperaCallbacks;
+class OperaGearsAPI;
+class OperaWorkerThreadInterface;
+class OperaLocalServerInterface;
+
+// Struct containing function pointers used to hold callback functions
+// from Opera to Gears.
+struct OperaCallbacks {
+  typedef void (*InitializeFunc)(OperaGearsAPI*, OperaCallbacks*);
+  typedef OperaWorkerThreadInterface *(*CreateWorkerFunc)();
+  typedef NPObject *(*CloneObjectFunc)(NPObject *object);
+  typedef void (*OpenSettingsDialogFunc)();
+  typedef void (*LocalServerInitializeFunc)
+      (OperaLocalServerInterface **opera_local_server_instance);
+
+  // Functions called by Opera when a worker thread is created.
+  CreateWorkerFunc create_worker;
+  // Functions called by Opera when an object is cloned in a worker thread.
+  CloneObjectFunc clone_object;
+  // Functions called by Opera to open the Gears settings dialog.
+  OpenSettingsDialogFunc open_settings_dialog;
+  // Functions called by Opera to initialize the URL data storage.
+  LocalServerInitializeFunc local_server_init;
+};
+
+// This interface is used by Opera to get the data from Gears needed
+// when requesting a URL.
+class OperaHttpRequestDataProviderInterface {
+ public:
+  // Returns true if the request is supposed to be asynchronous.
+  virtual bool IsAsync() = 0;
+  // Called repeatedly to iterate through the additional headers explicitly
+  // set by the Gears code for this request. As long as the funtion returns
+  // true name and value will hold the name/value pair of the header.
+  virtual bool GetNextAddedReqHeader(const unsigned short **name,
+                                     const unsigned short **value) = 0;
+  // Returns the URL string for the request.
+  virtual const unsigned short *GetUrl() = 0;
+
+  // Returns the HTTP method string for the request.
+  virtual const unsigned short *GetMethod() = 0;
+  // Only applicable if the method is POST. Returns either the length of
+  // the post data or copies chunks of the actual post data.
+  // If called with max_size set to -1 it will return the length of the
+  // data to be posted.
+  // If called with a buffer pointing to a preallocated buffer and the
+  // length of the buffer in max_size, the actual data to be posted will be
+  // copied to the buffer. Returns the amount of data copied to the buffer.
+  // Must be called until it returns a length less than max_size.
+  virtual long GetPostData(unsigned char *buffer,
+                           long max_size) = 0;
+};
+
+// This interface is used by the Opera implementation of the Gears code to
+// return the data fetched by Opera after a HTTP request.
+class OperaUrlDataInterface {
+ public:
+  // Returns the HTTP status code
+  virtual unsigned int GetStatus() = 0;
+  // After calling, status will contain a pointer to the HTTP status text
+  virtual void GetStatusText(const char **status) = 0;
+  // After calling, content will contain a non-terminated buffer of the
+  // data from the requested URL. content_length will hold the length
+  // of the data in the content buffer.
+  virtual void GetBodyText(const char **content,
+                           unsigned long *content_length) = 0;
+  // After calling, a continous 0-erminated string of the headers returned
+  // from the server separated by linebreaks.
+  virtual void GetResponseHeaders(const char **headers) = 0;
+  // After calling, charset will contain the character set specified from
+  // the server as a string.
+  virtual void GetResponseCharset(const char **charset) = 0;
+  // Returns true if the loading of the URL is completed.
+  virtual bool IsFinished() = 0;
+  // Called by the Gears code when it is finished processing the URL data.
+  virtual void OnCompleted() = 0;
+};
+
+// Listener interface for callbacks during loading of a URL requested from
+// the Gears code.
+class OperaHttpListenerInterface {
+ public:
+  // Constants returned from Gears when OnRedirected is called.
+  // OK if we should redirect, CANCEL if not.
+  enum RedirectStatus {
+    REDIRECT_STATUS_OK,
+    REDIRECT_STATUS_CANCEL
+  };
+
+  // Constants for error codes sent to Gears in an OnError() call.
+  enum LoadingError {
+    LOADING_ERROR_GENERIC,
+    LOADING_ERROR_OUT_OF_MEMORY
+  };
+
+  // Called when a chunk of data is received from the server. Will be called
+  // repeatedly until the URL is finished loading.
+  virtual void OnDataReceived() = 0;
+  // Called when the URL is redirected. The new URL string will be in
+  // redirect_url. Return REDIRECT_OK if we should redirect to the new URL
+  // or REDIRECT_CANCEL if we should not.
+  virtual RedirectStatus OnRedirected(const unsigned short *redirect_url) = 0;
+  // Called when an error occurs during loading of the URL. err will hold the
+  // error code.
+  virtual void OnError(LoadingError err) = 0;
+  // This will be called back from Opera immediately when the an HTTP request
+  // has been made from Gears. It will contain a pointer to the an object
+  // implementing the OpUrlData interface.
+  virtual void OnRequestCreated(OperaUrlData *data) = 0;
+  // This will be called once when the request in Opera is deleted for some
+  // reason, for instance when we are finished.
+  virtual void OnRequestDestroyed() = 0;
+};
+
+// Listener interface for callbacks during the display of a dialog requested
+// by the Gears code.
+class OperaDialogListenerInterface {
+ public:
+  // Called when the user closes the dialog. A pointer to the result string
+  // will be in result.
+  virtual void OnClose(const unsigned short *result) = 0;
+};
+
+// The interface between Opera and Gears. Gears will call one of these
+// functions when it wants Opera to perform a specific task.
+class OperaGearsAPI {
+ public:
+  // Request Opera to load a URL.
+  // plugin_instance must contain the plugin object from the NPAPI invocation.
+  // It is used internally in Opera to identify the document context which the
+  // URL should be loaded in.
+  // req_data must point to an implementation of the
+  // OpHTTPRequestDataProviderInterface that will deliver the information
+  // about the URL to load.
+  // listener must point to an implementation of the OpHTTPListener interface
+  // that Opera will use to report results of the loading.
+  // If req_data->IsAsync() returns true this function will return immediately
+  // or else it will block until the URL is loaded.
+  virtual void RequestUrl(NPP plugin_instance,
+                          OperaHttpRequestDataProviderInterface *req_data,
+                          OperaHttpListener *listener) = 0;
+
+  // Request Opera to display a dialog.
+  // plugin_instance must contain the plugin object from the NPAPI invocation.
+  // It is used internally in Opera to identify the document context which the
+  // dialog should be opened in.
+  // html_file must point to a string identifying the html file to be used as
+  // a template for the dialog.
+  // width and height will be used to set the size of the dialog.
+  // arguments_string will contain a JSON formatted string with the arguments
+  // that will be passed to the dialog.
+  // After this call returns result will contain the JSON formatted results
+  // returned from the dialog.
+  virtual void OpenDialog(NPP plugin_instance,
+                          const unsigned short *html_file,
+                          int width, int height,
+                          const unsigned short *arguments_string,
+                          const unsigned short **result) = 0;
+
+  // Create a Opera native WorkerPool object.
+  // Returns the NPAPI representation of the workerpool object.
+  // plugin_instance must contain the plugin object from the NPAPI invocation.
+  // It is used internally in Opera to identify the document context which the
+  // WorkerPool should be created in.
+  // factory specifies the NPAPI representation of the Gears factory object.
+  virtual NPObject *CreateWorkerPool(NPP plugin_instance,
+                                     NPObject *factory) = 0;
+
+  // Sets the global object of the plugin_instance.
+  virtual void SetCurrentGlobalObject(NPP plugin_instance,
+                                      NPObject *global_object) = 0;
+
+  // Request Opera to return the cookie value associated with the url url.
+  // After the function returns, cookie_out will point to the cookie data.
+  virtual void GetCookieString(const unsigned short *url,
+                               const char **cookie_out) = 0;
+};
+
+#endif  // OPERA_CALLBACK_API_H__
==== 
//depot/googleclient/gears/opensource/third_party/opera/opera_local_server_interface.h#1
 - 
c:\MyDocs\Gears3/googleclient/gears/opensource/third_party/opera/opera_local_server_interface.h
 ====
# action=add type=text
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ 
googleclient/gears/opensource/third_party/opera/opera_local_server_interface.h  
    2008-12-10 16:42:43.000000000 +0000
@@ -0,0 +1,60 @@
+#ifndef OPERA_LOCAL_SERVER_INTERFACE_H__
+#define OPERA_LOCAL_SERVER_INTERFACE_H__
+
+// Interface used to read URL data from URLs stored in the Gears DB
+//
+// The cache reader is initialized by calling GetHeaderData() and then
+// all the other methods will return valid data.
+class OperaCacheReaderInterface {
+ public:
+  // Called to fetch the list of headers for a specified URL.
+  // The name of the URL to fetch the headers of should be in url.
+  // After this function returns, header_str will point to an array of header
+  // lines.
+  // The number of entries in the header array will be returned in 
header_length
+  virtual bool GetHeaderData(const unsigned short *url,
+                             char **header_str,
+                             int *header_length) = 0;
+
+  // Called to indicate that the stored headers should be deleted.
+  virtual void ReleaseHeaderData() = 0;
+
+  // Called repeatedly to fetch the actual data the URL points to.
+  // After the call returns, the pre-allocated header_str buffer will be
+  // filled with the next chunk of data.
+  // The buffer will be filled with the first buffer_length chars of data, or 
less
+  // if there is less data remaining for the URL.
+  // The return value will indicate how many bytes were actually read. To get 
all
+  // the data, this function must be called until More() returns false.
+  virtual int GetBodyData(char *header_str, int buffer_length) = 0;
+
+  // Returns true if there is more stored data to fetch with GetBodyData().
+  virtual bool More() = 0;
+
+  // Called when we no longer need the Cache reader and it can be deleted.
+  virtual void Destroy() = 0;
+
+ protected:
+  virtual ~OperaCacheReaderInterface() {}
+};
+
+// Interface for fetching URL data from the Gears DB
+//
+// If CanService() returns true, a cache reader can be created to get the data.
+class OperaLocalServerInterface {
+ public:
+  // Returns true if the URL indicated by url can be served from
+  // the Gears database.
+  virtual bool CanService(const unsigned short *url) = 0;
+
+  // Returns a cache reader to read data from the DB.
+  virtual OperaCacheReaderInterface *GetCacheReader() = 0;
+
+  // Called when the local server is not needed and can be deleted.
+  virtual void Destroy() = 0;
+
+ protected:
+  virtual ~OperaLocalServerInterface() {}
+};
+
+#endif // OPERA_LOCAL_SERVER_INTERFACE_H__
==== 
//depot/googleclient/gears/opensource/third_party/opera/opera_worker_interface.h#1
 - 
c:\MyDocs\Gears3/googleclient/gears/opensource/third_party/opera/opera_worker_interface.h
 ====
# action=add type=text
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/third_party/opera/opera_worker_interface.h    
2008-12-10 16:42:45.000000000 +0000
@@ -0,0 +1,36 @@
+#ifndef OPERA_WORKER_INTERFACE_H__
+#define OPERA_WORKER_INTERFACE_H__
+
+#ifdef EXTERNAL_GEARS_SUPPORT
+#include "modules/ns4plugins/src/plug-inc/npapi.h"  // for NPP for Opera
+#else
+#include "third_party/npapi/nphostapi.h"  // for NPP for Gears
+#endif
+
+// Interface for the Opera native worker thread implementation to
+// communicate with the Gears plugin
+class OperaWorkerThreadInterface {
+ public:
+  virtual ~OperaWorkerThreadInterface(){}
+  // Will be called when Opera wants to get permanently delete
+  // the worker thread
+  virtual void Destroy() = 0;
+
+  // Called from Opera when we want to create a new worker thread.
+  // instance will be the plugin context from which the creation
+  // was triggered.
+  // global_object is the new global object created for the worker
+  // url is the URL which the worker will be created from
+  virtual NPObject* CreateWorkerFactory(NPP instance,
+                                                                               
NPObject *global_object,
+                                                                               
const unsigned short *url) = 0;
+
+  // Is called when Opera needs to suspend the creation of the
+  // worker thread for some reason
+  virtual void SuspendObjectCreation() = 0;
+
+  // Is called when Opera will resume the creation of the worker thread
+  virtual void ResumeObjectCreationAndUpdatePermissions() = 0;
+};
+
+#endif  // OPERA_WORKER_INTERFACE_H__

Reply via email to