ããå¯ä»¥å¨å°åæ ä¸è¾å ¥chrome://extensionsæ¥çå·²å®è£ çæ©å±ç¨åºãä¸å¾ç¤ºä¾è¯´æäºæçæµè§å¨ä¸å·²å®è£ äºGoogle Mail Checkeræ©å±ç¨åºï¼æ们å°ä½¿ç¨å®æ¥æµè¯æ°å¢çAPIï¼æµè¯å¯ä»¥ä½¿ç¨ä»»ä½æ©å±ç¨åºï¼èä¸éæå®è¿æ示ä¾çGoogle Mail checkerï¼ã
ããä»ä¸å¾ä¹åæ¶ç¤ºä¾äºå¦ä½æå¼Chromeç½ä¸ååºï¼æ们éè¦è¿å ¥è¯¥é¡µé¢æ¥çå·²å¼å好çAPIãè¿å ¥é¡µé¢åæF12æå¼å¼åè å·¥å ·ï¼å¹¶å°å¼åè å·¥å ·åæ¢å°æ§å¶å°ã
ããå¨å¼åè å·¥å ·çæ§å¶å°ä¸ï¼è¾å ¥âchrome.management.unâå ¶å°æ¾ç¤ºmanagement namespaceææ¯æçAPIã
ããä¸é¢æ们è¦åçï¼å°±æ¯å¨managementä¸å¢å showButton APIï¼ç¨äºæ¾ç¤ºæéèæ©å±æ ä¸ï¼æï¼æ©å±ç¨åºçIconãå¢å showButton API大ä½ä¸åæ两大é¨éª¤ãæ¥éª¤ä¸ä¸ºåæ´C++代ç ï¼æ¥éª¤äºä¸ºåæ´management.jsonæ¥å£æè¿°æ件ãä¸é¢éæ¥è®²è§£åºäºChrome R28æºç çå ·ä½åæ´å 容ã
ããé¦å ï¼å¨src\chrome\browser\extensions\api\management\management_api.hä¸å¢å ä¸ä¸ªæ°ç±»ç声æãå½showButtonå¨Javascriptä¸è¢«è°ç¨æ¶ï¼è¯¥ç±»å°è´è´£è¿è¡åç»å¤çï¼å ¶RunImplæ¹æ³å°ä¼è¢«è°ç¨ã
ãã
ãã
ããclass ManagementShowButtonFunction : public ManagementFunction {
ããpublic:
ããDECLARE_EXTENSION_FUNCTION("management.showButton", MANAGEMENT_UNINSTALL)
ããprivate:
ããvirtual bool RunImpl() OVERRIDE;
ãã};
ãã
ããæ¥çï¼å¨src\chrome\browser\extensions\api\management\management_api.ccä¸å¢å æ°ç±»çå®ç°ãRunImplæ¹æ³æ ¹æ®JavaScriptæä¼ å ¥ç两个åæ°è°ç¨SetBrowserActionVisibilityå½æ°ï¼å®ç°å¯¹æ©å±ç¨åºIconçæ¾ç¤ºåéèã第ä¸ä¸ªåæ°ä¸ºæ©å±ç¨åºçIDï¼ç¬¬äºä¸ªåæ°æ¯ä¸ä¸ªå¸å°åéï¼ç¨äºæ示æ¯æ¾ç¤ºï¼trueï¼ææéèï¼falseï¼æ©å±ç¨åºçIconã
ããæäºä»¥ä¸çåæ´åï¼å¨ç¼è¯Chrome项ç®ä¹åï¼éæå¨éæ°ç¼è¯api项ç®ï¼å 为Chrome项ç®å¹¶ä¸ä¾èµäºapi项ç®ãéæ°ç¼è¯å°ä½¿å¾å¨èªå¨çæçGeneratedFunctionRegistry:: RegisterAllå½æ°å å¢å 对ManagementShowButtonFunctionç注åã
ããç¨åºç¼è¯å®æåï¼æ们å¯ä»¥å¨å¼åè å·¥å ·çæ§å¶å°ä¸æµè¯showButtonå½æ°ãä¸å¾ç¤ºä¾è¯´æäºéè¿è°ç¨è¯¥å½æ°éèåæ¾ç¤ºGoogle Mail Checkeræ©å±ç¨åºçIconã
ããä¸é¢ç¤ºä¾äºå¦ä½å¨å·²åå¨çmanagement namespaceä¸å¢å ä¸ä¸ªAPIãå¨Chromeä¸ï¼JavaScript APIç使ç¨åå¨æéçæ¦å¿µãå¦ææ°å¢APIçåæ¶ä¹éæ°å¢namespaceçè¯ï¼éè¦æ³¨æå¨APIPermissionInfo::RegisterAllPermissionsæ¹æ³ä¸æ³¨åæ°å¢namespaceçæéï¼å¦åä¼åºç°é¡µé¢æ æ³è®¿é®æ°å¢APIçé®é¢ã